My customer has many pages with <script>
elements including javascript.
<script src="myscriptforthispageonly.js"></script>
I’m trying to get all scripts to load in the footer using wp_enqueue_script()
, but I’m not sure how to enqueue a script from within a page.
Again, this is within a WordPress page. Is it possible to enqueue an external script from a page or post?
If that’s not possible, is it possible to delay loading the script until the onload event fires?
General answer: you can call
wp_enqueue_script()
directly inline in the template, as of WordPress 3.4 (IIRC).So, if you have:
You could replace it with:
Edit
From this comment:
Your best course of action would be to define a shortcode for the user to put into the post content, instead of putting a
<script>
call itself directly in the post content. Then, in your shortcode callback, you can callwp_enqueue_script()
.