How to Add Custom Javascript into Your WordPress Site
In some situations, you may need to add custom Javascript to your site. Normally, this would involve modifying your theme files.
However, there is a less intrusive alternative. “Header and Footer Scripts” is a plugin to add custom JavaScript to WordPress without modifying your theme.
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
- Insert script in header (load inside head tag) or footer (load before closing body tag)
- Click Save settings button when you’re done
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>
Load custom JavaScript without a file
- Go to Settings → Header and Footer Scripts
- Add your code script directly in header (load inside head tag) or footer (load before closing body tag)
- Click Save settings button when you’re done