0

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' );
 }
}
2
  • 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. – mor7ifer Feb 9 '12 at 10:21
  • reconsider the 'elseif' condition as your one is always true. – Michael Feb 9 '12 at 14:35
2

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

1
  • 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

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.