If you just started with WordPress then there may be several things, which would require you to insert scripts/code into the theme’s header and footer. For a web designer it’s pretty easy to edit the theme’s template and add the code anywhere as per the need, however most of the times WP beginners find it difficult to modify the theme’s files. Generally premium WordPress themes comes with built-in options to quickly add header and footer scripts but most of the free WordPress themes doesn’t come with such kind of options. If you are facing any of the above mentioned issues then this guide can be useful for you as here, we have shared an alternative way of doing the same without even touching the theme’s files.
When you need to add the scripts/code in the header or footer?
The following tasks require you to add the scripts or code to your theme’s template header or footer –
- While adding Google analytics script to your blog.
- While manually adding social media buttons (Google plus button, Facebook like, Twitter etc.) to the blog.
- While adding metadata tags (Facebook open graph tags, Twitter card, Dublin core etc.) into your theme’s template
The above mentioned tasks are the most common among WP beginners, however there are numerous things which would require the code or script insertion in header or footer areas of your website.
Can I manually add script or code in theme’s header and footer without plugin?
Yes, Scripts and codes can be added to theme directly without using any plugin. For adding the code in header – Search for the file header.php in Appearance » Themes » Editor and add
For adding the code in footer, you may need to modify the footer.php file, which can be found at the same place – Appearance » Themes » Editor.
Note: The above mentioned file names are the most commonly used ones, however they may vary depending on the theme you are using.
How to insert script or Code in Header or Footer without modifying the theme?
Below are the few WordPress plugins for this –
The 2nd and 3rd plugins provide few other functionality apart from adding scripts in head and footer. Since, this post is all about a convenient way to add the code in theme’s head and footer , let’s discuss about the 1st plugin, which is mainly developed for this task.
Insert Header and footers
As you can see in the above screenshot that this plugin enabled a settings page for adding scripts. You can choose to have a script either in head or footer depending upon the need.
Final Words
I know most of the SEO experts won’t agree to use the plugin for each and every task (More number of plugins slow down your website a bit) but still I recommend these plugins for the beginners and for those, who are using free WordPress themes because, I believe that it’s not a good idea to edit your theme files each and every time you wanna add something.