Some times we need to remove some javascript from our wordpress website or blog to speed up our website. Here below is a trick which you can use to remove unused js from your wordpress website.
First of all you have to find the javascript file which you want to remove and to find this open your webpage in google chrome and press ctrl+u to view the source code of the webpage, then find the script tag of js file and there you will see the id in the script tag and this is what you need to remove the js. Now paste the code given below in your functions.php file located at root_directory_path/wp-content/themes/your_theme/functions.php
And we have used here two wordpress core functions wp_dequeue_script and wp_deregister_script.
Here ‘woocommerce’ is the id of the script tag which you have found in source code of webpage.
function wra_filter_scripts(){
if( is_home() == true || is_single() == true ){
wp_deregister_script('woocommerce');
wp_dequeue_script('woocommerce');
}
}
add_action('wp_print_scripts', 'wra_filter_scripts', 100000);
add_action('wp_print_footer_scripts', 'wra_filter_scripts', 100000);
Please like share subscribe and give positive feedback to motivate me to write more for you.
For more tutorials please visit my website.
Thanks:)
Happy Coding:)
Top comments (1)
Hello Chetan! Are you open to new job opportunities?