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

I am using a WordPress plugin for including PHP code within posts and pages, and it's working great - however, I need to insert some styles and scripts, and in order to do that, I need to add a hook to wp_head. I tried it, creating a function and using add_action('wp_head','my_func'); but it didn't work - my stuff is not being included.

I think its because wp_head is being called before my script it being included.

I would like to do this without changing any of my themes files.

Is there any way to do this? I am using the latest WordPress version.

share|improve this question
Are you trying to add the hook within a post? That won't work. Hooks must be placed inside your theme's functions.php file. – Joseph Leedy Aug 31 '12 at 12:26
Yes, that is what I was trying. WP hooks only work inside the Functions file? – Jeff Aug 31 '12 at 12:45
How would one go about adding scripts and styles to the head tag from a specific page then? – Jeff Aug 31 '12 at 12:46
up vote 1 down vote accepted

To enqueue styles and scripts properly, use the wp_enqueue_scripts action like so:

function wpa_63708_enqueue_scripts() {
    wp_register_script( 'my-script','/path/to/script' );
    wp_enqueue_script( 'my-script' );

add_action( 'wp_enqueue_scripts', 'wpa_63708_enqueue_scripts' );
share|improve this answer
Use wp_enqueue_style for stylesheets, but on the same wp_enqueue_scripts action hook. – Otto Aug 31 '12 at 17:01

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.