Answer the question
In order to leave comments, you need to log in
How can I make this script turn off on certain pages and not turn on?
I want to remove Wordpress CSS loading from all pages, except for a few, for this I found several scripts and combined them into one. But it works the other way around, turns off the script on the specified pages, but it needs to be left on the specified ones.
function custom_dequeue() {
if(is_page(5)){
wp_dequeue_style('woocommerce-layout');
wp_dequeue_style('woocommerce-smallscreen');
wp_dequeue_style('woocommerce-general');
wp_dequeue_style('woocommerce-inline-inline');
wp_dequeue_style('photoswipe-css');
wp_dequeue_style('photoswipe-default-skin');
wp_deregister_style('woocommerce-layout');
wp_deregister_style('woocommerce-smallscreen');
wp_deregister_style('woocommerce-general');
wp_deregister_style('woocommerce-inline-inline');
wp_deregister_style('photoswipe-css');
wp_deregister_style('photoswipe-default-skin');
}
add_action( 'wp_enqueue_scripts', 'custom_dequeue', 9999 );
add_action( 'wp_head', 'custom_dequeue', 9999 );
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question