How to Add JavaScript to Your WordPress Site

Are you using WordPress, but need to add JavaScript to your site like to implement something from our JavaScript Events API? Follow this guide to see how to add JavaScript to your WordPress website.

You have 2 options for inserting JavaScript:

NOTE: If you are using non-WordPress sites, then our platform specific guides will be a good resource for you to review.

Use a WordPress Plugin

You could use a WordPress plugin if you want to insert JavaScript into your site. There are a variety of plugins out there. One of the more popular plugins is Insert Headers and Footers.

CRITICAL NOTE: OptinMonster does not officially endorse any plugin that you use and OptinMonster is not responsible for and will not provide any support for any plugins you use to insert JavaScript. If the plugin you decide to use messes up your site in any way, that is something that you will need to address between you and that plugin’s author.

Essentially, you will need to copy the JavaScript code you want to us, then follow the instructions of whatever plugin you choose to use.

WARNING: if you code something incorrectly here, the PHP error could break your site. Please be sure to make a full back-up before editing PHP files. In addition, it’s best to make changes to PHP code on a staging site when possible, before moving to your live site.

While everyone’s WordPress setup is different, your theme should have a footer.php file. To access this you will need to go to do the following:
WordPress Dashboard > Menu Item: Appearance > Sub-Menu Item: Editor.

When you get to your editor screen, look for your Theme’s Footer (footer.php). Click that.

Now your Theme’s Footer (footer.php) should be showing up. Go to the code area below <?php wp_footer(); ?>. Below that, but above the closing </body> tag is where your code should go.

Therefore, it should looking something like this:

After you have added your code, double checked for proper syntax, then click Update File. Your JavaScript is now loaded on all of your pages on your site.

Now that you know how to add JavaScript to your site, check out what you can do with OptinMonster’s JavaScript Events API.