In this post you will get detailed information about how to add (Google Analytics code, custom JS code snippet, Facebook pixel code, third party script code) in your WordPress site.
JS code added using following methods will be available in sites all pages.
This method is simple and not required to follow complex processes. You just need to install a plugin and you are ready to go.
By this WordPress plugin method you can add your script code in the site’s header, body and footer without modifying any theme files.
For manual process, first open header.php or footer.php based on requirement from “Appearance > Theme Editor > Theme Files”. Now, add your script code in header.php or footer.php file and click the “Update File” button.
Note: in the header.php file, you need to add your code before tag. And in footer .php, you need to add your code before tag.
For including JS file in specific post or page you not required any plugin. You can add include JS script code direct in your post content using WordPress “Custome HTML” block.
Example code of include JS file: <script src=”your-js-file-url-here.js”></script>
Note: plugins that can add script in your content need to be updated from time to time. So, as a good practice with some days interval, check that plugin has continued support and updates on WordPress.org.
How to check that script code properly added in WordPress?
To check this, you need to open your site’s page where code added.
Next, confirm your code from page view-source. For that, open the page view-source, search your code and confirm that page have same code which added from admin dashboard.
- Google Analytics script code in header.
- Script code Google AdSense Autoads.
- Third party service integration (Ad, chat etc.,)
Given are most common cases where you have need to add third party or custom JS code in your WordPress site.