3

I'm converting a bootstrap html website into Wordpress.

Now, all recommend using wp_enqueue_script() for registering javascript files. i.e.

function themeslug_enqueue_script() {
    wp_enqueue_script( 'my-js', 'filename.js', false );
}

add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_script' );

But I have some js files loading in the head and some other ones in the footer of the original html code.

I was going to use wp_head and wp_footer, is it ok to do so or better stick to wp_enqueue_script?

2

It looks like you've overlooked the 5th input parameter of:

 wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); 

Namely the boolean $in_footer part, that will put the script in the footer, if set as true, else in the header.

You can also use $deps to handle dependencies.

Check out the Codex for more info.

=> I would stick to wp_enqueue_script() and not manually place the scripts into the header or footer.

  • 1
    Ah ok I didn't know that parameter existed. Well, then it's obvious that wp enqueue is the proper way to go. Thanks – Vegan Sv May 25 '15 at 1:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.