How to remove javascript or scripts in wordpress?

In this article we will teach you how to remove javascript or scripts in wordpress.

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);

That’s it Now you have learned the trick how to remove javascript or scripts in wordpress.

And if you want more tutorials and tricks about wordpress then visit our WordPress Page and follow us on facebooktwittertumblrlinkdedin and if you like this article then share this.

16 thoughts on “How to remove javascript or scripts in wordpress?”

  1. I merely wanted to thank you a lot more for that amazing web site
    you have developed here. It really is full of ideas for those who are truly interested in that subject,
    specifically this very post. Your all so sweet plus thoughtful of others and reading your blog posts is a great delight with me.
    And such a generous surprise! Mary and I usually have excitement making use of your suggestions in what
    we have to do in the future. Our list is a kilometer long so your tips will certainly be put to
    great use.

  2. Hi there! I’m at work surfing around your blog from my new
    iphone! Just wanted to say I love reading
    your blog and look forward to all your posts!
    Carry on the outstanding work!

  3. Hi there! I’m at work browsing your blog from my new apple iphone!
    Just wanted to say I love reading your blog and look forward to all your posts!
    Keep up the fantastic work!

  4. What’s Taking place i’m new to this, I stumbled upon this I’ve discovered It positively
    useful and it has aided me out loads. I am hoping to contribute
    & help other customers like its aided me. Good job.

  5. I think this is one of the so much significant information for me.
    And i’m glad studying your article. However want to commentary on few basic things,
    The site taste is perfect, the articles is truly nice
    :D. Just right process, cheers.

  6. I feel that is among the most important info for me.

    And i’m glad studying your article. However should remark on some general things, The web site style is ideal, the articles is really great :D.
    Good job, cheers.

Comments are closed.