Support » Fixing WordPress » Problem with wp_enqueue_script and footer

  • I am trying to enqueue a script from within a short code function:

    function shortcode_mytest() {
       wp_enqueue_script('shortcode.mytest', PLUGIN_PATH.'js/mytest.js', null, null, true);
       echo 'test';
    add_shortcode('mytest', shortcode_mytest);

    The word “test” appears on the screen, but the script is never included at the footer of the page. I have checked my theme and it does call wp_footer() as required.

    The only way that I can get this to work is to include the following line within my “functions.php” file:
    add_action('wp_print_footer_scripts', 'wp_print_scripts');

    To me this doesn’t seem right because surely if ‘wp_enqueue_script’ is designed to add to footer, then surely wouldn’t ‘wp_footer()’ automatically insert the enqueued scripts?

    Any input would be greatly appreciated!

    Kind regards,
    Lea Hayes

  • The topic ‘Problem with wp_enqueue_script and footer’ is closed to new replies.