DEV Community

Cover image for How to remove extra javascripts wordpress?
Chetan Rohilla
Chetan Rohilla

Posted on • Edited on • Originally published at w3courses.org

7 2

How to remove extra javascripts 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);
Enter fullscreen mode Exit fullscreen mode

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

Tiugo image

Modular, Fast, and Built for Developers

CKEditor 5 gives you full control over your editing experience. A modular architecture means you get high performance, fewer re-renders and a setup that scales with your needs.

Start now

Oldest comments (1)

Collapse
 
garima2808 profile image
garima2808

Hello Chetan! Are you open to new job opportunities?

Image of Stellar post

How a Hackathon Win Led to My Startup Getting Funded

In this episode, you'll see:

  • The hackathon wins that sparked the journey.
  • The moment José and Joseph decided to go all-in.
  • Building a working prototype on Stellar.
  • Using the PassKeys feature of Soroban.
  • Getting funded via the Stellar Community Fund.

Watch the video

👋 Kindness is contagious

Dive into this insightful write-up, celebrated within the collaborative DEV Community. Developers at any stage are invited to contribute and elevate our shared skills.

A simple "thank you" can boost someone’s spirits—leave your kudos in the comments!

On DEV, exchanging ideas fuels progress and deepens our connections. If this post helped you, a brief note of thanks goes a long way.

Okay