Is it safe/recommended to use wp_enqueue_script function outside the functions.php file?

As of WordPress 3.4, calls to wp_enqueue_script() can be made inline. So, it is perfectly acceptable to call it where needed, such as inside a shortcode callback, or conditionally based upon returned queries, as you’ve done here.

Leave a Comment