WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I'm trying to get my head round <?php wp_head(); ?>.

I understand that it loads in the stuff needed for plugins etc., but I'm using a theme that seems to be using it to load in scripts for theme elements as well.

There's a folder within my theme called 'scripts' that appears to have all of the javascript needed for the theme. In the outputted code is all of the javascript files etc.

So my question is: How do I hook in a javascript file (or anything for that matter) into <?php wp_head(); ?>?

share|improve this question
up vote 1 down vote accepted

You use wp_enqueue_script for Javascript files in your theme functions.php files. I suggest wrapping up all the requests in a function and hook it like so

add_action( 'wp_enqueue_scripts', 'script_enqueuer' );
share|improve this answer
Ok so I'm looking at the pinboard theme and in this is what it's doing: add_action( 'init', 'pinboard_register_scripts' ); if ( ! function_exists( 'pinboard_enqueue_scripts' ) ) : function pinboard_enqueue_scripts() { wp_enqueue_script( 'ios-orientationchange-fix' ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'flexslider' ); wp_enqueue_script( 'fitvids' ); Can't I just add in a new script like wp_enqueue_script( 'example' ); to that list? I just tried it and it doesn't seem to work. – sanjaypoyzer Feb 13 '13 at 17:05
You can. But if you want to call it just by the name, you have to register the script using wp_register_script – Sunyatasattva Feb 13 '13 at 17:11
Ah I see! Thanks so much. – sanjaypoyzer Feb 13 '13 at 17:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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