How To Add Code To Your Website Header and Footer
Most tracking services will ask you to add code to your website header and footer. They will do so to enable you to track your visitors’ behaviour, identify the pages they visit most and more.
While it is possible to add these code snippets to your WordPress header or footer by using code, for a beginner like yourself, using a plugin might be an easier solution. That’s why in the rest of this article, I will show you 3 plugins you can use to do that.
- Header and footer scripts by Digital Liberation — Can help you add code to individual pages
- Insert headers and footers by WPBeginner — Simplest to use
- Head, footer and post injection by Stefano Lissa — Most editable
3 Plugins To Add WordPress Header and Footer Code
1. Header and footer scripts
1.1 Install and activate the plugin from your plugin addition page.
- Search “header and footer scripts“.
- Verify that it’s from Digital Liberation and that it is compatible with your version of WordPress.
- Click install, then activate.
1.2 Add your code snippet
- Within your WordPress dashboard, go to Settings —> Header and footer scripts
- If you’ve been asked to add code specifically in the header of your site, locate the “Scripts in header” box and paste your code.
- Alternatively, if you’ve been asked to add code to your site footer, paste it in the “Scripts in footer” box.
- Make sure you save your settings.
1.3 To add code to a specific page
Sometimes, you may be asked to add header and footer code to a specific wordpress page. If that is the case, follow this process:
- Go to your page list and click “edit” under your page of interest.
- At the top or bottom of your page creation area, locate the “Insert script to head” box.
- Paste your code and update your page.
2. Insert Headers and Footers
This is by far the simplest plugin to use, although not the most extensive. To add your code to your website header and footer, simply do this.
- Visit your plugin addition page
- Search for “Insert Headers and Footers” (Make sure the author name is WP Beginner).
- Install and activate.
- In your dashboard, go to “Settings —> Insert headers and footers”.
- Paste your code in either the “Scripts in header” or “Scripts in footer” box.
- Click Save.
- This will inject your code across your entire website.
3. Head, Footer and Post Injection
Of the 3 plugins in this post, this one offers the most flexibility over where to add your code.
For the purpose of this post, I will only cover the header and footer code injection points. Do this:
- Open plugins, then add new.
- Search “Head, footer and post injections” (Authored by Stefano Lissa).
- If it is compatible with your version of WordPress, then install and activate.
- Within your dashboard, go to “Settings —> Header and footer”
- Make sure you’re on the “Header and Footer” tab.
- If you want to add code to every page on your website, then paste your code in the “Head – Every page” box.
- To add code to your homepage only, paste it in the “Head – Only home page” box.
- To add code to your footer, scroll down to “Before the closing tag (footer)” and paste it in the desktop box. Note: The “Mobile” check box is used to specifically add code to the mobile version of your website. If you want any code applied to both the desktop and mobile versions of your site, paste it in the desktop box and leave the “Mobile” checkbox unchecked.
Each of the plugins mentioned above would be a suitable solution for beginner users.
It is important that you keep your plugin installed and activated for your added code snippet to work at all times.
To remove a previously added custom code on your website header or footer, visit your settings and safely erase it.
For more on the topic of WordPress plugins, please visit our sister website.