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!
2 Responses
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
Hi, You can add the script in functions.php file inside your theme’s folder. OR you can use a plugin to be able editing functions.php ( https://en-gb.wordpress.org/plugins/my-custom-functions ) from your WordPress dashboard.