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.

Im trying to clean up my scripts and I'm using a function to but ran into a problem with using both !is_page or !is_single to only show certain scripts on singles and pages. What did I do wrong here.

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
function my_deregister_javascript() {
if ( !is_page() ) {
wp_deregister_script( 'thickbox' );
wp_deregister_script( 'shutter' );
wp_deregister_script( 'swfobject' );
wp_deregister_script( 'ngg-slideshow' );
wp_deregister_script( 'ngg_script' );
wp_deregister_script( 'jquery-shuffle' );
  }
elseif ( !is_single() || !is_page()) {
wp_deregister_script( 'autosize_js' );
wp_deregister_script( 'admin_js' );
 }
}
share|improve this question
1  
What was the goal and what is the current behavior? Also, did you really mean elseif? I think you just wanted if for that second one. –  m0r7if3r Feb 9 '12 at 10:21
    
reconsider the 'elseif' condition as your one is always true. –  Michael Feb 9 '12 at 14:35
add comment

1 Answer 1

up vote 2 down vote accepted

The problem is probably because wp_print_scripts is too late to deregister scripts as this is when they are outputted to the template.

You should consider using wp_enqueue_scripts or wp_register_script instead. This question may help:

wp_enqueue_scripts, wp_register_scripts, wp_print_scripts: i'm confused

share|improve this answer
    
oh ok I get thanks Stephen! –  Pollux Khafra Feb 9 '12 at 10:41
    
If this answer solved your problem, you should accept it, by clicking the checkmark below the vote count. –  Chip Bennett Feb 16 '12 at 3:41
add comment

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.