How to Add Custom JavaScript into Your WordPress Site?

When you want to change the theme of your site, one thing that needs to be done is to add custom JavaScript to it. However, there are other options available if you do not want to add it to your site. For instance, simply add the ‘Heat and Footer Script’ as an option which is much less intrusive compared to the other.

Well, this article is not about the various alternatives, but mainly about the JavaScript which can be added to your WordPress site. How you can exactly do the task? We will share the details with you in the section below.

Options to add JavaScript to WordPress Site

How to Add Custom JavaScript into Your WordPress Site

Image Source

It is not difficult to add custom JavaScript to a WordPress site. All you need to know the way through which it can be done. Two main options and ways in which you can add JavaScript to WordPress sites include the following:

1. Add Custom JavaScript File

First of all, you have to save the file with .js format. After this, you may add this into the folder http://wp-content/themes/your-theme/js/. When you do this, go to the settings where there will be two options in front of you. Either you can add it to the header, or the footer. This is how simple it can be.

2. Add Custom JavaScript Without File

This option is simple to add the custom JavaScript without file. You do not need to save this file as .js format. Rather, you can directly upload it to the folder http://wp-content/themes/your-theme/js/. The header will be the place where you will add it and then go to the save setting when you complete the process.

One Thing You Should Never Do

Although it is quite clear that a much better option to add the custom JavaScript to your WordPress site is to use the ‘SCRIPT’ tag. This is added directly into either header or footer.php. However, you should never do that. As WordPress has a specific loading sequence, therefore, this sequence needs to be respected, and this option must not be availed.

The reason behind this is that if you will add to the header or footer.php which will lead to changes within the whole theme. The core and plugins of WordPress might also face conflicts due to the addition of custom JavaScript in this way. Instead of this option that brings so many issues in your WordPress site, therefore, try to use only the above-mentioned two options. Make sure that you do not add it to the header or footer, even if it seems the only option.

When it comes to importing templates, getting a reliable WordPress website builder will allow you to import templates for just about any topic or any niche with endless customization options.

Conclusion

As you can see that the custom JavaScript is not difficult to add to the WordPress site. It will take a few minutes if you know how to do it. We have explained the information in detail where you will get to know about each point. Follow the step by step, and do not make amendments on your own.

Leave a Comment

Your email address will not be published. Required fields are marked *