how to add custom javascript in wordpress
First, let's install the plugin:
Log in to your WordPress site.
Go to Plugins > Add new
Search for "Header and Footer Scripts".
Click "Install Now" and activate the plugin.
Custom JavaScript into WordPress
Option #1. Upload a custom Javascript file
Save your custom JavaScript code into a file with the .js format
Upload it into your site to this folder: wp-content/themes/your-theme/js/
Go to Settings > Header and Footer Scripts.
Now you have two options to load the file:
Scripts in header (load inside head tag)
Scripts in footer (load before closing body tag)
Use the location that match better your needs using this syntax as example:
<script src="http://www.yoursite.any/wp-content/themes/your-theme/js/file.js"></script>