Do you have a custom script and want to add it to a WordPress website but don’t know how? Well, you came to the right place. I will show you the best way to solve this problem.
There can be many reasons to add the custom script. Google AdSense or Analytics may have scripts and it has to be added to your website, or perhaps you have a custom script to improve WordPress theme capabilities.
Table of Contents
Never Edit Theme Code
The one thing you must never do is to not change WordPress core or theme code. If you change, it might not work properly, and also, when the theme or WordPress gets updated, your code will be deleted.
And it is not a good idea, in general, to change the already working code. It has its own flow and any custom script might damage it. You can also add some custom code via theme customizer but I don’t recommend it.
Also Read: Add AdSense On WordPress
There is a better way to accomplish this task and here I am to show you how.
Let’s dive in and see how clean and easy it is to add a custom script to a WordPress website.
Install The Plugin
In order to make this happen, you have to install the plugin Insert Script In Headers & Footers. With this plugin, it is very easy to add as many scripts as you wish.
This plugin allows you to add scripts and custom code snippets in your header or footer. This way, you don’t edit the code.
The plugin adds it and it will work always. Even when WordPress or a theme is updated.
Insert Custom Script
Now, it is time to add scripts via this plugin. In order to insert code to WordPress, go to your dashboard, and in the Settings tab there will be a new section – Insert Script In Headers & Footers.
Go there and you will see the simplest interface you have ever seen.
There are just two areas where you can insert code – one for the header and one for the footer. Depending on your custom script, you need to insert your code in the header or footer.
Most code snippets need to be inserted in headers. But some scripts work better when they are in the footer.
Just paste your code and click Save. That is it. Your snippet is inserted and it will work perfectly.
And the best thing is that you can add any amount of code snippets to this plugin. There are no limitations. Add Google scripts, your custom scripts, or any other code you want.
Why This Method Is Good?
Adding code snippets with a plugin is the best way because it does not interfere with the WordPress or theme core. It is separated it is much cleaner.
If you insert custom code in a theme, it may damage the theme or even WordPress and you will have problems. It might not work properly and you will be forced to uninstall and install WordPress. You will lose your content which is a very bad thing.
Also, when your theme will be updated, your custom script will be deleted. And it means that you have to add code after every update. This is not the right way. That’s why there are plugins for that.
So, always use the plugin when you want to add any kind of code. And there are other plugins that do the same job.
Here are some plugins that can add custom scripts to your website:
Conclusion
So, now you can add custom code snippets to your WordPress website without a problem. It is an easy, clean, and better way. With this method, you will have no problems and the website will work smoothly.