Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Add Header and Footer Code in WordPress (the Easy Way)

Have you ever been asked to add some code snippets to <header> or <footer> 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.

You may also come across WordPress tutorials that might ask you to add some custom CSS or Javascript code to your WordPress header or footer.

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.

How to Add Header and Footer Code in WordPress

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:

  1. Manually, by editing your theme’s header.php and footer.php files
  2. With your theme’s built-in header and footer code feature
  3. 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.

Insert Headers and Footers

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.

Video Tutorial

Subscribe to WPBeginner

If you don’t want to watch the video tutorial, then you can continue reading the text version below:

Adding Code to Header and Footer in WordPress

First thing you need to do is install and activate the Insert Headers and Footers plugin. For more details, see our step by step guide on how to install a WordPress 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.

Insert Headers and Footers plugin settings

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. You may also want to see our comparison of the best email marketing services and the best business phone services.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

250 CommentsLeave a Reply

  1. Hi! I have a question! I am trying to add the global site tag and phone snippet to my code on each page so I can track my google ad calls. I have the “Headers and Footers” plugin, can I just paste it here and I am good? Or does it matter where I post it (Header vs. Body. Footer)? Thanks so much!

  2. So close to being what’s needed! But Google strongly recommends using different metadata for every page. “Identical or similar descriptions on every page of a site aren’t helpful when individual pages appear in the web results. In these cases we’re less likely to display the boilerplate text. Wherever possible, create descriptions that accurately describe the specific page. ” Please consider updating your plugin accordingly.

    • Our plugin is not for metadata, it is mainly for code to add things like Google Analytics tracking or for verification codes. If you want a plugin for adding metadata to individual posts, we would recommend taking a look at All in One SEO as that will give you far better control over your metadata :)

      Admin

  3. I have a question. How do you remove code that you added using the insert headers and footers plugin? When I open up the theme editor I can’t find the code I added using this plugin.

    • Code added using the plugin would be removed when removed from the plugin’s settings or the plugin is uninstalled.

      Admin

  4. Hello, hey I added the plugin above to my site and added the code to the header section. Then I tested with your site and it said it was saved successfully.

    But I don’t see the bot when I go to the live site. Could u tell me what I’m doing worng? Tnx.

    • It would depend on the specific code you are adding, we would recommend checking with the support for the code for if you added it correctly as not all code is made to have something visible.

      Admin

  5. I wanted to change the color of my address bar using this plugin but each time I paste it gives me an error message

    Is my code okay?

    • It would depend on the specific code and where the code is intended to be added. You would want to reach out to who you received the code from for where it should be placed.

      Admin

  6. I bought a theme but it does not let me add any button action in the header nor in the menu, do you think this plugin could help me???

  7. How can add the code in the header as high as possible? I need to put Code first of few lines in the header. How can I control the position of the code?

    Thanks

    • If you need a very specific location for the code, you would want to manually add the code to your files.

      Admin

  8. USELESS for a theme that does not have headers in the first place, like wordpress 2021. Useless.

    It was implied that this plugin would do that. It. Does. Not. ALL it does in insert a GIANT version of the picture you choose ABOVE your menu and site name.

    • The 2021 theme does have a header but, the Insert Headers and Footers plugin is for inserting code such as Google Analytics, not for adding photos to the header of your website. We would not recommend using this plugin for adding a header image as that would cause the errors you are running into.

      Admin

  9. Hey There,

    I have already installed “Insert Footer and Header plugin”, if I wanna to remove from site then the inserted code would also be removed from header section or still saved without plugin?
    Kindly light me.

  10. I’m being told by Google Analytics to add a Global Site Tag code immediately after the tag. Does this plugin do that? Otherwise, I have no idea how to add this code to *every* page on my site!

  11. Thank you SO much for these simple instructions and the plug-in. I could not figure out why my website kept deleting from Pinterest!

    • Code added using the plugin will be on every post and page and not individual codes for individual posts and pages.

      Admin

  12. Hey,

    I can’t find the “Insert Headers” section below my post’s editor? So how can I enable that function allowing me insert different code for specific post?

    • Our plugin is for the entire site at this time and not individual posts or pages.

      Admin

  13. How do I install different code for each page type instead of putting all the code in every page?

    • You would need to manually add that if we’re understanding what you’re wanting.

      Admin

    • Yes, we will look into updating the tested with version as soon as we are able

      Admin

  14. I am getting the following error when hitting SAVE from this plug-in:

    A potentially unsafe operation has been detected in your request to this site

    • You would want to check if you have any security plugins active on your site or if your host has one set up. You may also want to ensure you copied the code you are attempting to add correctly.

      Admin

  15. On your demonstration you didn’t have anything come up on the top.
    This is the instructions from the code generator I am using;
    Paste the copied code into bottom of your HTML page just before the closing tag
    I tested the code and it does not work, “Am I doing something different? “

    • We would first recommend reaching out to the support of what has generated the code to ensure there isn’t anything specific about the code that needs to be set on your page for it to work correctly.

      Admin

  16. Hello. I need to edit the header code on a specific set of pages only. I have currently added the script I need to the header.php file, however this applies the code to all pages globally.

    Is there any way I can add the script to a specific set of pages only?

    • Unless I hear otherwise, we do not have a recommended method for page specific code at this time.

      Admin

  17. Thank you so much!!!

    This stuff scares me as I think I am going to doom my website forever!!

    So easily explained will definitely be subscribing.

    I need to work on this every day.

  18. If my theme does not allow custom header images, will this plugin allow me to make custom header images. Lost on how to do this. We have an old theme with custom header function

  19. Would i be able to use a relative path? so I can move the site to a different host without changing header? if so where is the origin?

    i tried to include some some examples but sucuri blocked the post as malicious. i guess it doesn’t like seeing paths.

    • It would depend on the code but you should be able to user relative paths if you wanted.

      Admin

  20. Yaaaaaaay! I am so excited. I was having so much trouble getting my Mailchimp pop-up to work, but this plugin did the job easy-peasy!

  21. Hi, I have installed the Headers and Footers plugin and added code for the footer. The text that I want displayed is at the very bottom, below the Bento copyright line. Is there a way to have my footer appear at the top of the footer display? Thanks

    • For footer customizations, you would want to reach out to your theme’s support to see if they have any recommended options you can use.

      Admin

  22. I have already put Google analytics code in the header section using insert header and footer plugin how can I add adsense code there again?

    • That would be something you can do but not all beginners want to or understand how to create a child theme, that is why we recommend this method.

      Admin

  23. This plugin’s activation active auto bulk mail sending from my hosting server. This is working like a spam. So I have to delete this from my website.

    • This plugin does not have anything like that, we would recommend scanning your site to ensure you do not have any malicious code on your site

      Admin

  24. I added this plugin to my site but nothing showed when I clicked on the plugin? I’m using an old version of WP but not sure if this is the reason why.

    • You should find the plugin’s section under Settings>Insert Headers and Footers

      Admin

  25. Hi team,

    Does the FB Pixel Base Code was copied and paste on the header tag in that plugin.
    will it automatically apply to every page of the website? Please reply!

  26. How can I add a code in body section (not in the header/footer section ) with this plugin?
    I want to add certain code in the body section to avoid render blocking.

    • The plugin should currently have a third input box where you can include code that should be in the body of your site.

      Admin

  27. Hi,
    My site was built by a web developer who already included all sorts of code snippets in the section of my site.
    If I add new snippets of code using this plugin, will it overwrite the code that’s already there or just add the new code to the existing code?
    I don’t want to make a mess of my site… :-)
    Thanks!

    • If you add code using this plugin it would be added to your site, it would not replace code

      Admin

  28. Hi! I tried to add the plugin to my site but you need to have a business page to add any plugins? Can I add the code without a plugin?

  29. hi
    First i have install header and footer plugin than after past my google analytics code . but my problem is once past the code and see my website, the code showing disable? How to solve it?

    • If the code is not being added to your header, you would want to clear any caching on your site as that is the most common root of that issue.

      Admin

    • You would want to check with your specific theme’s support for the header not appearing on a specific page as it could be a page specific template causing you issues.

      Admin

  30. Thanks guys for your plugin! I used it to add FB Pixel to my site, but now I have a landing page and I need a different Pixel event (Lead) on the Thank You page after visitors confirm their details. Can I use the plugin to add the script to a specific page?

    • Not at the moment, for the time being, the plugin adds the code to all pages by default

      Admin

  31. Hi, is there a way to change the font size of the footer?
    I tried keying in a chunk of disclaimer text but it is too large.

    Thanks in advance!

  32. I used your insert headers and footers plugin and it was soooo easy and helpful! Thank you so much!

    • If you mean a WordPress.com site then they currently don’t allow Adsense on their free plan.

      Admin

  33. I’m trying to connect my website to adsense in order to set up an account.
    So far google did not see the code.

    • You may want to ensure you’ve cleared any caching on your site as one of the most common reason

      Admin

  34. You need to change your messaging/advertising regarding header/footer plug-in being free to install. It is not free unless you have purchased the Business plan for your page.

  35. How many codes we can add in single header or footer section, I mean can i use two or three codes in single header section like facebook code google code etc.

    • You could certainly add as many codes as you need in the header section depending on your needs.

      Admin

  36. Was wondering if PHP can be added in the header section. Like adding Yoast’s Breadcrumb code to the header so I don’t have to go into my theme files.

  37. Can You add more than one header code, to the plug-in, for example
    AdSense code and YouTube Verification code.

  38. Hi, I’m trying to add a javascript to my site header but on click on save it says page not found

    • You may want to try resaving your permalinks and checking with your hosting provider that they are not receiving an error on your site that would be preventing the page from saving.

      Admin

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.