How to Remove / Dequeue / Deregister Script on WordPress

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

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;

It will printout the handle information

object(_WP_Dependency)#576 (6) {
string(14) "jquery-isotope"
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!

Any idea? Fill the comment below

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

More To Explore