WordPress.org

Ready to get started?Download WordPress

Forums

Problem with wp_enqueue_script and footer (1 post)

  1. Kruncher
    Member
    Posted 3 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic