Learn simple and easy method to add code in WordPress Header and Footer. I will explain how to do this with or without using WordPress plugins.
</body> tag. So I decided to write an exclusive article to address this issue. And to explain how you can easily add code in WordPress header and footer file.
Also, while designing your WordPress site, there are occasions when you need to use some code snippets (may be script for Google Analytics tracking) in WordPress header or footer.
Some WordPress themes like Themify, Mythemeshop or Elegantthemes etc. come with inbuilt feature to let you add code in WordPress Header and Footer from the theme control panel itself. Though some themes offer this feature, but still I would not recommend you to use theme control panel to add code in header and footer.
You might ask, why?
Because, if you are using theme control panel, you don’t have liberty of switching to another theme without losing footer and header codes. So, basically if you switch to another theme, you have to set up header and footer codes again.
But what about other themes which do not offer such features to add code in WordPress Header and Footer. If your WordPress theme or framework does not support such feature. Then continue reading…
In the following paragraphs, I will take you through how you can easily solve this issue. First, let’s see what type of different codes or scripts you may need to add in WordPress header and footer.
Types of Code and Script
You might want to add one or more type of codes in WordPress header and footer out of the following types.
- Google Analytics tracking code.
- Site Security Verification code.
- Webmaster Tools Verification Meta tags.
- Verification code for Bing, Alexa, Yandex etc.
- Schema mark-ups.
- Any other script or code.
Add Code in WordPress Header and Footer
Generally speaking, there are two popular methods to Add Code in WordPress Header and Footer.
- Using WordPress Plugins: You can manage all header and footer codes from one place. Also, using a plugin to add code in WordPress header and footer is a better idea than using theme control panel. Because you can change your theme anytime without losing those header and footer codes.
- Manually – By Editing Theme Files: Though there is no plugin is required. But here you don’t have bliss of managing all codes from one place is difficult.
Method 1: Using WordPress Plugin
To Add Code in WordPress Header and Footer, you can use simple and efficient WordPress plugins.
These plugins work well with almost all free or paid WordPress themes.
- Head, Footer and Post Injections This plugin offers many options to insert code at different positions apart from header and footer. You can even insert code before/after each post and before/after each post excerpt etc.
- Insert Heads and Footer This plugin adds only two sections. Out of which one can be used to add code to <head> section and the other one is for above
</body>tag (i.e. footer).
Framework Specific Plugins
These plugins are designed to work with specific framework.
Simple Hooks This plugin works with Genesis Framework for WordPress. You can easily add code in WordPress header and footer using this plugin. The plugin also allows to add code at different hook positions like before_header, header, after_header, before_content, after_content and several others.
Method 2: Manually – By Editing Theme Files
This method involves editing of header.php and footer.php files. Therefore, I recommend you to apply this method to the child theme files instead of parent theme files. Moreover, if you add code to child theme files, your code remains untouched even the parent theme gets an update.
I hope you’re already familiar with the child theme and using a child theme on your WordPress site.
If you are not using a child theme, read this Ultimate Guide for Child Theme in WordPress. This guide covers what is child theme in WordPress, why you MUST use a child theme and how you can easily create and use a child theme.
Follow the following steps to edit WordPress header and footer files manually:
(Implement this method, only if you’re aware and confident enough about what you are doing. Further, don’t forget to take complete backup before implementing this method. So that you can restore your site, if something went wrong.)
- Go to WordPress Dashboard > Appearance > Editor.
- In the Editor Screen, open header.php or footer.php file by clicking it. (Depending up on to which file you want to add a code.)
- Once the file is opened in editor, you can add code in WordPress header and footer file.
- In the following example I have opened footer.php file. You can paste your code just before
Note – If you are adding a PHP code, than you can directly use the code. But if you want to add a HTML or Script File, you may need to cover that code inside the PHP tags.
- Click Update File. And you’re done.
Perhaps, the ability of customization is the major reason for humongous success of WordPress. These WordPress customization require a lot of plugin usages or code insertion at various positions in WordPress.
Definitely, WP-Head and WP-Footer have their own importance when it comes to code insertion in WordPress.
Which method is suitable for you?
The honest answer of this question is that nobody knows better than you. However, I have already mentioned using a plugin gives advantage of managing all codes from one place, you don’t need to edit theme files.
On the other side, if don’t want to install an additional plugin. And you are already using or can use a child theme and then you may apply manual method.
Up to you.
I hope this guide helps you to add code in WordPress header and footer. Which other technique, plugin do you use to add code in WordPress, feel free to share with our readers. Have a query about this subject, post it via comment below. I will be happy to answer.