Site icon Anthony Carbon

Dequeue or deregister a style or script in WordPress

Dequeue or deregister a style or script in WordPress is now easy and no need more time to find solutions online.

Example 1: I want to remove styles using `dequeue` function. If you can see, I want to remove the `anton-accordion-style-css` styles. Please see codes below.

<link rel='stylesheet' id='anton-accordion-style-css'  href='https://www.anthonycarbon.com/wp-content/plugins/4nton-accordion/assets/css/style.css?ver=4.9.1' type='text/css' media='all' />

Code to be paste in functions.php

add_action( 'wp_enqueue_scripts', 'mc_deregister_or_dequeue_styles', 20 );
function mc_deregister_or_dequeue_styles() {
	if( is_home() || is_front_page() ){ // Optional, if you want to remove only in homepage
		wp_dequeue_style( 'anton-accordion-style' );
	}
}

Example 2: I want to remove script using `dequeue` function.

<script type='text/javascript' src='https://www.anthonycarbon.com/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart.min.js?ver=3.2.6'></script>

Code to be paste in functions.php

add_action( 'wp_enqueue_scripts', 'mc_deregister_or_dequeue_script', 20 );
function mc_deregister_or_dequeue_script() {
	if( is_home() || is_front_page() ){ // Optional, if you want to remove only in homepage
		wp_dequeue_script( 'wc-add-to-cart' );
	}
}

Hope it solve your problem. Happy coding 🙂

Exit mobile version