Have you ever been asked to add some code snippets to or section of your WordPress website?
Often you are asked to add header and footer code in WordPress when trying to integrate with web services like Google Analytics, Facebook Pixel, Google Search Console, etc.
By default, WordPress doesn’t provide an option to insert code in your website’s header and footer. Luckily there is an easy solution for beginners.
In this article, we will show you how to easily add header and footer code in WordPress. The goal is to safely add the code without directly editing your WordPress theme files.
The Best Way to Add WordPress Header and Footer Code
If you want to add WordPress header and footer code, there are three possible solutions:
- Manually, by editing your theme’s header.php and footer.php files
- With your theme’s built-in header and footer code feature
- Using a plugin
The first option is not beginner friendly because it requires you to add header and footer code by directly editing the header.php and footer.php files manually.
Another disadvantage of using this method is that your code will be removed if you install an update to your theme.
The second option is using your theme’s built-in feature. Some WordPress themes like Elegant Themes and Genesis Framework by StudioPress offer a built-in option for quickly adding code and scripts to your WordPress header and footer.
If you are using a theme with a built-in feature, then it seems like a safe and simple solution. However if you change your theme, then all the code snippets added to your website will be gone. This includes site verification in Google Search Console, website analytics via Google Analytics, etc.
This why we always recommend users to use the third option, a headers and footers plugin. This option is by far the easiest and safest method to add header and footer code in WordPress.
After a lot of request from readers, our team has built a 100% free Insert Headers and Footers plugin to let users easily add code to the header and footer in WordPress.
Here are some benefits of using the Insert Headers and Footers plugin:
1. Easy, Fast, and Organized: It lets you add codes to your site’s header and footer easily and quickly. Plus, it keeps you organized by allowing you to store all your footer and header codes in one place.
2. Prevents Errors: It helps prevent errors which may occur if you edit your theme files manually.
3. Upgrade or Change Your Theme Without any Worry: The plugin will save your header and footer code in a separate place, so you can update or change your theme without worrying about the code being erased.
With that said, let’s see how to easily add header and footer code in WordPress using Insert Headers and Footers plugin.
Adding Code to Header and Footer in WordPress
First thing you need to do is install and activate the Insert Headers and Footers plugin.
Once the plugin is activated, go to Settings » Insert Headers and Footers from your admin panel. After that, you will see two boxes for adding code to header and footer.
Simply paste the code in one of the two boxes. Once done, don’t forget to click the Save button to store your changes.
The plugin will now automatically load the code in the respective locations on your WordPress site.
You can always edit and remove any code that you don’t want to keep.
You’ll need to keep the plugin installed and activated at all times. Deactivating the plugin will stop adding all custom code to your site.
If you accidentally deactivate the plugin, the code will still be safely stored in your WordPress database. You can simply reinstall or reactivate the plugin, and the code will start appearing again.
Note: You may have to clear your WordPress cache after saving changes, so the code properly appears on the front-end of your website.
We have found the biggest reason why a lot of beginners use the Insert Headers and Footers plugin is to add Google Analytics to their website. For that, we actually recommend using the free MonsterInsights plugin. It’s the best Google analytics plugin for WordPress which helps you properly setup Google analytics tracking with just a few clicks, and it shows you helpful stats right inside your WordPress dashboard.
We hope this article helped you to learn how to add header and footer code in WordPress easily.