How do I enqueue(or delay loading of) tags in individual page posts?

General answer: you can call wp_enqueue_script() directly inline in the template, as of WordPress 3.4 (IIRC).

So, if you have:

<script src="https://wordpress.stackexchange.com/questions/82668/myscriptforthispageonly.js"></script>

You could replace it with:

<?php wp_enqueue_script( 'this-page-script', get_template_directory_uri() . '/myscriptforthispageonly.js', array( 'jquery' ), null, true ); ?>

Edit

From this comment:

This is from within a page. As in a WordPress page. No templates. Imagine you are writing a WordPress blog post update, you switch to HTML vie

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 call wp_enqueue_script().

Leave a Comment