• Hi there,

    I am trying to add a JS file to the end of the page just before the closing body tag. I have read that I can set true in my enqueue line to set it in the footer, but when I set to true, is still adds it way up the page and not at the end.

    This is the line I am using:

    wp_enqueue_script( 'myscript', get_bloginfo('template_directory') . '/js/scripts.js', array( 'jquery' ), '', true );

    Can anyone tell me what I have done wrong?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    That can happen if myscript is specified as a dependency by another script that is loaded in the head section.

    “way up” is ambiguous A script link could appear way up a page and still be in the footer if it’s a sizable footer with a lot of script references ??

    CP

    (@cparwebsites)

    Have you set your priority number higher than others loading in the footer?

    For example, here I used 999999…

    add_action( 'wp_enqueue_scripts', 'cpar_enqueue_later', 999999 );
    
    function cpar_enqueue_later() {
    
    wp_enqueue_script( 'myscript', get_template_directory_uri() . '/js/scripts.js', array( 'jquery' ), '', true );
    
    }
    • This reply was modified 2 years, 3 months ago by bcworkz. Reason: code format fixed
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘enqueuing Js in the footer’ is closed to new replies.