Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm looking to add some scripts and styles to particular taxonomy page. For example, I want to have a banner rotator only appear for posts that fall under the "issue" custom taxonomy. I've tried using the is_tax('issue') to control when the scripts and styles are enqueued but that doesn't seem to be working. Here's a sample of my functions.php file:

function init_customizations() {
  if (is_tax('issue')) {
    wp_register_script('rotator_scripts',get_bloginfo('template_directory').'/includes/issue-rotator.js', array(), '1.0.0' );
    wp_enqueue_script('rotator_scripts');
    wp_register_style('rotator_styles',get_bloginfo('template_directory').'/includes/issue-rotator.css', array(), '1.0.0', 'screen');
    wp_enqueue_style('rotator_styles');
  }
}
add_action( 'init', 'init_customizations', 0 );

This doesn't actually write anything to the header so I suspect I may be calling it incorrectly.

Update Here is the final code with the correct answer applied to it:

function init_customizations() {
  if (is_tax('issue')) {
    wp_register_script('rotator_scripts',get_bloginfo('template_directory').'/includes/issue-rotator.js', array(), '1.0.0' );
    wp_enqueue_script('rotator_scripts');
    wp_register_style('rotator_styles',get_bloginfo('template_directory').'/includes/issue-rotator.css', array(), '1.0.0', 'screen');
    wp_enqueue_style('rotator_styles');
  }
}
add_action( 'wp_enqueue_scripts', 'init_customizations', 0 );
share|improve this question
    
I don't think is_tax() is initialized on init yet. Try changing the action tag to wp –  onetrickpony Feb 21 '11 at 17:57
    
That did the trick! Unfortunately I can't seem to located the "Accepted" button, is there a certain rep needed to mark something as correct? –  hereswhatidid Feb 21 '11 at 18:38
1  
You cannot accept a comment. You can a) ask One Trick Pony to re-post it as an answer or b) accept another correct answer. –  Michal Mau Feb 21 '11 at 22:46

1 Answer 1

up vote 3 down vote accepted

For a function that enqueues scripts, the action hook you use should actually be "wp_enqueue_scripts" for the front of the site, and "admin_enqueue_scripts" for the admin side of things. This is the proper time to enqueue scripts.

While you can technically do it anytime before wp_head, this is the best place because it's pretty much the last possible chance to do it, thus ensuring that everything else that can be done before script output has been done, making your logic all work properly.

share|improve this answer
    
That's correct. My code example was a bit misleading in that it didn't actually have the calls for the JavaScript, just the CSS. I've updated the example to better fit the original question. –  hereswhatidid Feb 22 '11 at 15:09
    
Actually, it's fine to enqueue styles on the wp_enqueue_scripts hook as well. Same basic reasoning. –  Otto Feb 22 '11 at 15:22

Your Answer

 
discard

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.