a plugin that I bought is loading a few js and css files on all pages, so I wanted to write a new function to deregister the handles, and enqueu them where I wanted. however I am not sure If I have to deregister => register and then enqueue. or do I just dequeue them and enqueue them where I want
// deregister scripts and load them where required
add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
function my_deregister_javascript() {
wp_deregister_script( 'contact-form-7' );
wp_deregister_script( 'upme_tipsy' );
wp_deregister_script( 'upme_google_fonts' );
wp_deregister_script( 'upme_font_awesome' );
wp_deregister_script( 'upme_css' );
wp_deregister_script( 'upme_style' );
wp_deregister_script( 'upme_responsive' );
wp_deregister_script( 'upme_validate' );
wp_deregister_script( 'upme_validate_pass' );
wp_deregister_script( 'upme_password_meter' );
if ( is_page('contact-us') ) {
wp_enqueue_script( 'contact-form-7' );
}
elseif (is_page(array(680, 671, 675, 688, 'profile'))) {
wp_enqueue_script( 'upme_tipsy' );
wp_enqueue_script( 'upme_google_fonts' );
wp_enqueue_script( 'upme_font_awesome' );
wp_enqueue_script( 'upme_css' );
wp_enqueue_script( 'upme_style' );
wp_enqueue_script( 'upme_responsive' );
wp_enqueue_script( 'upme_validate' );
wp_enqueue_script( 'upme_validate_pass' );
wp_enqueue_script( 'upme_password_meter' );
}
}
You should be able to just dequeue the script or style if it’s not the pages you want it on.