You may need to add some scripts to your WordPress site to improve the functionality, make modifications to your website’s appearance or add new features to the site particularly if you are using 3rd-party services such as Google Analytics, CRMs, Ad Snippets, Tracking Pixels, and more. There are many ways to add scripts to your site:
- There are some third-party plugins that allow you to add scripts to your site, but it might be difficult to locate one that perfectly meets your needs. Third-party plugins might potentially pose a security risk if they are not kept up to date on a regular basis.
- You may copy/paste them directly into your website by editing your theme.
Adding Script to Your Site with Header Footer Code Manager
When modifying your website’s core code, even a single error might cause your site to cease operating entirely. Downtime might result in lost clients. When you edit the code, it is critical to pay strict attention to detail. You should always keep a backup of your site, if anything goes wrong you can restore the previous state by restoring the backup. There are many ways to take backup of a WordPress site.
If you use a plugin, it will add your scripts to your site. You don’t have to go and edit the theme files and mess up the site. The best plugin for this job is Header Footer Code Manager. You can add your scripts easily to your website with HFCM and manage them. Let’s see how you can do that.
First, you need to install and activate the plugin.
- After installing and activating the plugin, navigate to HFCM on the left navbar in the WordPress Dashboard area.
- Click on HFCM > Add New
- Enter a suitable name for your snippet, which would help you distinguish it from other snippets. For Example: Google Analytics Snippet (if you are entering a google analytics code snippet)
- Choose the display options as per your requirements, and then add the code snippet in the Snippet / Code textarea.
- Click on the Save button to save your snippet to the database. You can navigate to HFCM > All Snippets to view/edit/delete your saved snippet
You need to put your code in this box and save it. Then turn on the snippet and that’s it. The snippet will now show in the header of the site.
Inserting A Script by Editing Your Theme
You can use one of the built-in WordPress options to edit your theme and add the script to your functions.php file. This method can break your site though if you don’t put in the exact code that is necessary. An errant period or comma may completely break your site and that is why this method is not recommended.
Be very careful about copying snippets from sources you don’t trust. Always take backup of your site and if you don’t know what the code is doing it’s better not to use it. Malicious codes can harm your website.