How To Add JavaScript to WordPress

Are you trying to a tracking code or a external widget to your website. In this post I'll show you how you can add any scripts or css code to your wordpress website.

Whether is a piece of JavaScript or CSS code, there are couple of ways to add JavaScript to WordPress.

Be aware that although some themes have an option to add the scripts, I recommend using a plugin because that way if you change the theme, you will not forget to add those scripts back (believe me, it has happened many times).

To add a script to WordPress we are going to use a plugin. This will help us add the script without having to dig into the code.

Follow the following steps to install the plugin and add your script.


Add the Plugin

In your WordPress Dashboard go to Plugins Add New Plugin

Search for “Scripts” or “Header and Footer Scripts

Search for the Scripts plugin

Install the Plugin

Install the Header and Footer  Scripts plugin

Click in Install Now

Activate the Header and Footer  Scripts plugin

When the installation is complete,
click in Activate


How to Add JavaScript to WordPress

There are two ways of adding the sript.

Option 1 – Globally – Adding the Script to load across your whole website. Example: You do this for tracking scripts like Google Analytics.

Option 2 – Adding the script to a particular Page or Post


Option 1 – Add The Script Globally

Header and Footer Scripts Plugin Dashboard

After the Plugin is installed head over to:

Settings -> Header and Footer Scripts

install the script

Paste your script at the header or footer and click in Save settings


Option 2 – Add JavaScript to a WordPress Page or Post

When you Open your page, Scroll all the way down to the section:
Insert Script to <head>

Paste your code and save your page.

add script to a particular wordpress page

That’s all. If you have any comments or questions, let me know.