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 🙂
Jack says
Hi,
I want to disable the Nextgen galleria js script on the front page of my website. But the dequeue_script does not seem to work for me. Is there a difference in dequeue and deregister commands?
tnx!
Jack
Anthony says
Hey bud,
to check all enqueue scripts, use this code into your functions.php
You can use `wp_enqueue_scripts` or `wp_print_scripts` to `deregister` or `dequeue` script.
Example:
JohnT says
Hi
Is above wp_dequeue_style( ‘anton-accordion-style’ ); missing “-css”.
I cannot connect ‘anton-accordion-style’ and ‘anton-accordion-style-css’ or does WordPress do this by himself.
Regards
John