Logo Pupungbp.com

Need a WordPress expert help?

How to Remove / Dequeue / Deregister Script on WordPress

Last Updated: June 28, 2020 | Reading Time: < 1 minute

Using a complex premium theme with tons of features sometimes could be a potential issue of script conflicts. Oftenly, it loads scripts that we don’t even use, resulting in ridiculous load time and (like I said) increase the potential of conflicts with plugins.

My client requested a plugin that utilize isotope.js recently and I can’t get it working properly as is. So I started to trace the issue, and found out that isotope.js also loaded by the theme, also by it’s framework. So we have 3 isotope.js declared within a single page, what a waste!

Get to know the handle

Find out the handle that load the isotope, we can use global variable $wp_scripts to print it out.

global $wp_scripts;
var_dump($wp_scripts);

It will printout the handle information

...
["jquery-isotope"]=>
object(_WP_Dependency)#576 (6) {
["handle"]=>
string(14) "jquery-isotope"
["src"]=>
string(88) "
...

So you will know that the handle name is jquery-isotope

Dequeue and deregister it

We can use wp_dequeue_script to prevent the handle to be print by WordPress or use wp_deregister_script to unregister it from WordPress, means that we completely remove it from WordPress list.

function deregister_isotope() {
wp_dequeue_script( 'jquery-isotope' );
wp_deregister_script( 'jquery-isotope' );
}
add_action( 'wp_print_scripts', 'deregister_isotope' );

That’s it, have a nice day!

Looking for an affordable WordPress solution?

We offer budget-friendly WordPress website development services to meet your needs. Prices start at $10.

Related Posts

2 Responses

  1. Sorry, I’m not a pro.
    Where do I need to put the ‘wp-scripts’ code? And to where does it print out?
    I only know to put the ‘wp_dequeue_script’ in the functions.php file

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.