Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fikrirasyid/17a6f25ef30be3b44024 to your computer and use it in GitHub Desktop.
Save fikrirasyid/17a6f25ef30be3b44024 to your computer and use it in GitHub Desktop.
WordPress - Removing / Dequeueing All Stylesheets And Scripts on Particular Page
/**
* Removing / Dequeueing All Stylesheets And Scripts on Particular Page
*
* @return void
*/
function fr_dequeue_enqueue_styles_scripts(){
global $wp_styles, $wp_scripts;
// Note: You may want to add some conditional tag so this will only happen on particular page
// Let's say you want to do this on contact page
if( is_page( 'contact' ) ){
// Dequeueing styles
if( is_array( $wp_styles->queue ) ){
foreach ( $wp_styles->queue as $style ) {
wp_dequeue_style( $style );
}
}
// Dequeueing scripts
if( is_array( $wp_scripts->queue) ){
foreach ( $wp_scripts->queue as $script ) {
wp_dequeue_script( $script );
}
}
// From here, you can add specific stylesheets / scripts that you want to apply on this page only
}
}
add_action( 'wp_enqueue_scripts', 'fr_dequeue_enqueue_styles_scripts', 1000 ); // Hook this late enough so all stylesheets / scripts has been added (to be further dequeued by this action)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment