How To Remove Unused JavaScript In WordPress

If you’re like most WordPress site owners, you have a lot of JavaScript files included in your theme and plugins. While some of these files are used on every page of your site, others are only used under certain conditions. In this article, we will show you how to find and remove unused JavaScript files from your WordPress site. This will help reduce the loading time of your pages, making your site faster and more responsive. Let’s get started!

The first thing you need to do is identify which JavaScript files are unused on your site. To do this, you can use a tool like GTmetrix or Pingdom. These tools will analyze your website and tell you which files are not being used. Once you know which files are unused, you can delete them from your server.

If you’re not sure how to delete files from your server, we recommend contacting your host for assistance. Once the unused files have been removed, you should see a significant improvement in the loading time of your pages. And that’s it! You’ve now successfully cleaned up your WordPress site by removing unused JavaScript files.

What Is JavaScript?

JavaScript is a programming language that enables you to create dynamic website content. It is usually embedded in HTML code and can be used to add interactivity to a website.

If you are using WordPress, there is a good chance that you have some unused JavaScript code on your site. This can happen if you have installed a plugin or theme that adds JavaScript to your site, but you never actually use it. Or, it could be that you have added some custom JavaScript code yourself, but no longer need it.

Whatever the case may be, having unused JavaScript code on your WordPress site can lead to slower page load times and other performance issues. In this article, we will show you how to remove unused JavaScript in WordPress.

  • First, you need to identify which JavaScript files are being used on your site. You can do this by using a tool like GTmetrix or Pingdom. These tools will analyze your website and give you a report of all the JavaScript files that are being loaded on your pages.
  • Next, you need to go through each of these JavaScript files and look for the code that is no longer needed. If you are not sure how to do this, we recommend hiring a developer to help you out.

Once you have removed the unused JavaScript code from your WordPress site, be sure to test everything thoroughly before making your changes live. This will ensure that there are no broken elements on your site caused by the removal of the JavaScript code.

What Does It Mean To Have Unused JavaScript?

JavaScript is a programming language that is used to make websites interactive. It can be used to create things like drop-down menus, forms, and slideshows. When you add JavaScript to your WordPress site, it is stored in files called .js files.

Sometimes when you are working on your WordPress site, you may accidentally add JavaScript code that you don’t end up using. This unused code is called “orphaned” or “dead” code. Orphaned code can cause problems on your website because it can slow down your website’s loading time and take up unnecessary space on your server. In some cases, it can even cause errors on your website.

Find Your Largest JavaScript Files

To get started, you need to identify your largest JavaScript files. To do this, you can use an online tool like GTmetrix or Pingdom. These tools will show you a list of all the files on your website, ordered by size.

If you’re not sure which file is causing the problem, you can try disabling each one individually and see how it affects your page speed. Once you’ve found the culprit, it’s time to start minifying your JavaScript.

how to remove unused javascript in wordpress

Minifying Your JavaScript Files

Minifying your JavaScript files means removing all unnecessary characters from the code, including whitespace, comments, and line breaks. This can reduce the file size by up to 50%.

There are many tools you can use to minify your JavaScript files, but we recommend using a plugin like Autoptimize or Fast Velocity Minify. With these plugins, all you need to do is install and activate them, and they’ll automatically minify your JavaScript files. If you’re not using a plugin, you can minify your files manually using a tool like JSCompress.

Once you’ve minified your JavaScript files, make sure to test your website to see if everything is still working properly. If there are any problems, you can always revert to the original file.

Reduce Third-Party JavaScript

Third-party JavaScript can be a huge performance drag on your site. If you’re not using a plugin or theme, get rid of it. Many WordPress sites use jQuery, for example, but don’t need it. You can dequeue unnecessary scripts by adding this code to your functions.php file:

function remove_unused_javascript() {

wp_dequeue_script( ‘jquery’ );


add_action( ‘wp_enqueue_scripts’, ‘remove_unused_javascript’, 20 );

Doing this will improve the loading time of your pages and give you a performance boost. You can also use a plugin like Asset CleanUp to manage and remove unused CSS and JavaScript files.

Reduce the Number of Plugins You Use

Another way to speed up your WordPress site is to reduce the number of plugins you’re using. Every plugin you add has to be loaded, which can slow down your page loading time. When you’re choosing plugins, look for ones that are lightweight and well-coded.

Also, make sure you only use plugins that are essential for your site. If you’re not sure if you need a plugin, ask yourself if there’s another way to achieve the same functionality without one. For example, if you want to add a social sharing button to your posts, see if your theme already has that functionality built-in.

Remove Unused JavaScript In Elementor/Divi Theme Builder

If you’re using a theme builder such as Elementor or Divi, there’s a good chance that you’re loading a lot of unused JavaScript. This can bloat your pages and slow down your site. Fortunately, there are some easy ways to remove unused JavaScript from your WordPress site.

  • In Elementor, go to Settings > Advanced > Global Theme Styles. From here, you can disable various features that load JavaScript. For example, disabling the parallax effect will prevent the associated JavaScript file from loading.
  • In Divi, go to Theme Options > Layout > Disable Unused Elements. Once again, this will prevent various pieces of unnecessary JavaScript from loading on your pages.

Both of these settings should help to speed up your WordPress site by removing unused JavaScript. If you’re not using a theme builder, there are still some things you can do to remove unnecessary JavaScript. Check out the next section for more tips.

Bottom Line

In conclusion, if you want to remove unused JavaScript in WordPress, you can do so by following the steps outlined in this blog post. By doing so, you can improve your website’s performance and speed. Additionally, you can also reduce the size of your web pages. Thanks for reading! We hope this article was helpful. Feel free to share it with your friends and followers! If there are any questions or comments, please leave them below. We would love to hear from you! Until next time, take care!

Also Read:

Table of Contents

Do You Have a Digital Problem or a Project In Mind?

Kick Back and Let Us Solve It

We Guarantee to Fix Your Website Problem

Complete the form for instant access to our 24/7 WP site repair service and get a free quote in your inbox within 15 minutes.

Get A Free, No Obligation Quote

Tell Us About Your Project and We'll Send You a Free Proposal With No Strings Attached!

Tell Us About Your Digital Problem or Any Project You Have In Mind

Simply fill out the form and we'll be in touch.

Get a FREE professional consultation about your Website.

Learn more about your site’s performance, traffic growth strategies, user experience and improvement opportunities from our team of Website experts.

Skip to content