Archived topic
Deregister JS and CSS entire site except on all posts
3 replies · Started by webcréateur on September 3, 2019
Hi there,
Can you pls give me a hint how to disable/deregister JS (wp_deregister_script) and CSS (wp_dequeue_style) entire site except on all posts? Is this possible withe GP Elments?
Best Regards.
Hi there,
can you explain why you would want to do this?
The theme relies on whatever CSS or JS it loads, without it the site will break.
We have to use a Plugin which seem to make the website very slow.
This snippet e.g. restrict loading of a calendar Plugin on all pages except on Page "Events":
add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
if ( !is_page('Events') ) {
wp_deregister_script( 'wpng-calendar' );
wp_deregister_script( 'date-js' );
wp_deregister_script( 'thickbox-js' );
wp_deregister_script( 'jquery-js' );
wp_deregister_script( 'wiky-js' );
}
}
But what I need is to load the Plugin on single Posts and restrict loading anywhere else.
So you should be able to change the conditional to not posts ie. this:
!is_page('Events')
becomes:
!is_single()
This article explains how to add PHP:
https://docs.generatepress.com/article/adding-php/