Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#44709 closed enhancement (duplicate)

Allow for late loading of scripts added via wp_add_inline_script()

Reported by: woodent's profile woodent Owned by: woodent's profile woodent
Milestone: Priority: normal
Severity: normal Version: 4.5
Component: Script Loader Keywords:
Focuses: Cc:

Description

Inline scripts added via wp_add_inline_script() are only output when the referenced script file is loaded. If an inline script is added after a referenced script file has already been output, the inline script won't be output.

Much like how wp_enqueue_script() can be used within a shortcode to enqueue a file in the footer even though it would normally be loaded in the head; I propose that wp_add_inline_script() should output the inline script even if the referenced script file has already been loaded.

Since we can't predict when a script file that was loaded in the footer might be loaded into the head due to a third-party script with it as a dependency, wp_add_inline_script() should also be flexible and not break things by simply not outputting the code in those cases.

Change History (1)

#1 @ocean90
6 years ago

  • Keywords dev-feedback needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from assigned to closed

Duplicate of #41990.

Note: See TracTickets for help on using tickets.