This content originally appeared on DEV Community and was authored by Chetan Rohilla
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:)
This content originally appeared on DEV Community and was authored by Chetan Rohilla
Chetan Rohilla | Sciencx (2022-03-26T10:13:16+00:00) How to remove extra javascripts wordpress?. Retrieved from https://www.scien.cx/2022/03/26/how-to-remove-extra-javascripts-wordpress/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.