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 | Owned by: | 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.
Duplicate of #41990.