How to Insert Code into the Head Section of Your WordPress Blog

This post may contain affiliate links, which means I will receive compensation if you click through and make a purchase.

How to insert code into the head section of your WordPress blog | Given a piece of code to enter into the head section of your theme, but have no clue what that means or where to find it? In this tutorial I'll show you how. Click on through to learn how

How many times have you come across something that requires you to insert code into the head section of your blog? Perhaps you need to add Google Analytics tracking code. Or maybe you want to verify your Pinterest business account. Regardless of the reason why, you’ll likely have to do this at some time or another. And while it sounds scary and confusing, it’s actually quite easy. In this tutorial, I’ll show you how to insert code into the head section of your blog so you’ll be up and running in no time!

[affiliate_disclosure]

How to Insert Code into the Head Section With the Genesis Framework

If you’re using the Genesis Framework, you’re in luck! Inserting code into the head section of your site is ridiculously easy! Go to Genesis > Theme Settings. Scroll down to the bottom and find the section titled Header and Footer Scripts. Paste your code into the first box titled Header Scripts. Click save and you’re done!

head-genesis

How to Insert Code into the Head Section Using a Plugin

Not using Genesis? That’s fine. There’s still an easy way to insert code into the head section. First, you’ll want to install the Insert Headers and Footers plugin. From the Add Plugin page, search for “insert headers and footers.” You’ll want the plugin that was created by WPBeginner, which should be the first result. Install and activate it.

header-plugin

Now go to Settings > Insert Headers and Footers. Paste your code into the first box labeled Scripts in Header. Save and you’re done!

head-plugin

How to Insert Code into the Head Section of Your WordPress Theme

Now what if you’re not using Genesis and you’d rather not install another plugin? You’ll have to insert your code manually into your WordPress theme. Now keep in mind that doing so can break your site, so it’s important that you make a backup before you make any changes. Also, it’s important to note that when and if you install a theme update, your edits will be deleted and you’ll have to add them again. If you’re using a child theme, you should be okay, but if not, you might want to consider using the plugin mentioned above.

To insert the code manually into the head section of your WordPress theme, find your themes header.php file. You can find it by going to Appearance > Editor and looking for it on the right side of the screen. Or you can access it via FTP. Once you have your header.php file open, find the line with


Enter a new line above it and paste your code. Save your changes. That’s it.

head-header-php

Sidenote: Some themes will come with settings where you can enter your code into a designated area, much like the Insert Headers and Footers plugin above. It’s definitely a good idea to look into your theme’s documentation to see if that option is available. For example, the Divi theme has the option available by going to Divi > Theme Options, clicking on the Integrations tab, and entering the code into the box labeled “Add code to the < head > of your blog.”

Looking to add code to your site header on a specific page? Click here for a video tutorial.

[Tweet “Learn how to insert code into the head section of your WordPress blog with this tutorial”]

Need some development help?

209 thoughts on “How to Insert Code into the Head Section of Your WordPress Blog”

  1. Pingback: Blog Love

    1. This is so helpful, but I installed the header footer plugin and it didn’t work. I also copy pasted the CODE into my site’s Header HTML and that didn’t work. Any other ideas of what could be going wrong?

      1. It’s tough to say. Since both didn’t work, I’m wondering if there’s a problem with the code? Or your site’s theme might be setup differently.

  2. This is really, really helpful. Thank you!
    A quick question: Can this method be used to add code for Google Tag Manager as well?
    I’m using Genesis, it rocks 🙂

    1. Hi Karen. I’m not familiar with Google Tag Manager, but if they provide you with code to put in the < head > section of your site, then I don’t see why it wouldn’t work.

  3. I installed Insert Header and Footer…I pasted code as instructed…clicked Save….and still got white screen of death. Thoughts?

  4. Hi, Allyssa. I’m trying to enter code manually but I’m not clear exactly where to paste it. I have found the theme header and opened the file. You say to paste the code in the new line above it. Above what? Did I miss something? Appreciate all the help I can get xx

    1. Looks like the blog post stripped out the code. You’ll want to add the code between these:

      
      
      

      So add your code just before the 2nd line in the code example above.

  5. Thanks, this was really helpful. I have just added code from Google Adsense, if another site wants me to add something to the header can I just paste it on a new line directly under the Adsense code? Or is it limited to just one piece of code?

    1. Yes, you would add the next block of code on a new line below what you already have there. It can take more than one bit. Just make sure you are indeed at the very bottom or else you’ll end up breaking the code that was previously there (and the new code likely wouldn’t work).

  6. I know VERY little about how to work my WordPress account and am learning by trial and error. This worked great for me. Thank you for your help!

  7. I had no idea there was a plug in to do all of this! I made a mess of my site before with all of the things I was trying to add. Now I’m off to clean everything up. Thank you SO much!!

  8. You have made things very easier to me. Earlier I used to contact website developer for header codes. But its so easy damn!!

    I love your work. Keep doing it

  9. Allayssa,

    Thank you so much for your post. You wouldn’t believe how frustrated I was trying to find out how to not only add code to the head section of my WordPress blog but also just finding the head section was a challenge within itself.

    I never had this problem back a few years ago. If I wanted to add some type of code to the head section of my website all I have to do is go into the editor section of my websites theme and then locate the head section and the rest was a piece of cake from there.

    Though thanks to your post, once I download the plugin for headers and footers I was basically ready to rock and roll.

    Thanks again,
    Stephen Chris

  10. So thankful for this! You made it so easy to figure out. Some struggle to teach what they know; I can see that you excel at it!

  11. Hi, I have added the code via genesis theme. Do I need to manually put ” ” into my code? I didn’t add it but when I put my code and clicked save I’m not seeing a blank add in the header. Does it take awhile to see a change? Thanks for your help

  12. Thank YOU! You’re a total rock star!! I have been trying to get my website verified on Pinterest for ages and just couldn’t figure it out. Thanks to your tutorial, I downloaded the plugin and made it happen.

  13. I’m late to the party, but thank you for this! Spent ages going through various options trying to work out how to copy and paste something into my header and this sorted it right out!

  14. Thank you, thank you, thank you! =)
    Couldn’t figure out where to paste or what a head section even is. lol. You saved me a ton of time with pointing me directly to the WP plug in. So glad I found your article.

  15. Hi Alyssa – I am trying to follow your advice of copying the code directly to the head section of my WordPress theme, Primas. But I only want the code to apply to specific pages of my site. Should I do anything differently? Thanks much!

    1. Hi Cristina. To apply it to certain pages, it would require some conditional coding, which could get complex if dealing with a ton of pages. A better solution would be to look for a plugin similar to the one mentioned in the post that has the ability to add code on a post-by-post basis. That would probably be your best bet.

  16. Thank you so much! The instructions to enter things into a header with the Genesis Framework was so helpful!

  17. Thanks Allyssa. You had just what I was searching for in your great short tutorial on how to get spripts into header of a Genesis theme for WP. Much appreciated.

  18. Allyssa thank you soooooo much. I am taking a blogging course and could not figure out how to do this. I was trying for two hours to do this one simple thing. Googled how to do it and found your site. Thank you, thank you, thank you!

  19. Thank you so much for this helpful article.
    Hell This was really helpful. I have just added code from Google Adsense if another site wants me to add something to the header can I just paste it on a new line directly under the Adsense code

  20. Thank you so much! I used the plugin that you mentioned. I am using it for google adsense (i pasted the code in the header). Will this one time copy/paste put the code on every page of my site or just the home page?

  21. I have been trying to figure this out on my own – all the while TERRIFIED I would mess my site up completely. I had no idea there was a plug in that would make it so simple and fast. A thousand thanks!

  22. Thank you, thank you, thank you! I’ve been struggling because I had NO idea how to do this. You made this super simple and I really appreciate you for doing this. Thanks, again! You have a new fan 🙂

  23. This was great and it worked – thank you! I got an error / warning page from WordFence but I allowed it, tried again, and it worked. Thanks, Allyssa!

  24. Hi Allyssa,

    Thanks for sharing this! But my concern is different- I want to add “defer/async” in html script code which is already present inside the theme’s html file. But I don’t know how to access that as all I can see is a PHP interface when i go to Editor.
    Can you help me step by step with that?

    1. my own website factworld.com.ng i cant find the header tag pls how can i add website discription on wordpress

    1. Thank you so much for a life-saving article. You have helped me immensely. I chose the plugin option so as to be on the safe side.
      Thank you again!

  25. Thanks a lot, Allyssa!
    It helped me a lot, I was so confused how to do it. I wasted all of my day by searching for a solution about this but I did not find anything. Then I found this fabulous post straight to the point and it solved my problem. Please keep posting these solution.
    Thanks again.

  26. YOU are an absolute ANGEL! I’ve been struggling over this for over an hour and when I ready your tutorial I literally said out loud: “that’s it????” (I use Genesis). YES, that WAS it and I’m now verified! Google help doesn’t hold a candle to you. I can’t thank you enough!

  27. Woohoo!! Thank you so much Allyssa! I’ve tried to do this on my own multiple times and found it so frustrating – then I find your quick tutorial and boom, done!

    Doing a happy little Snoopy dance over here 😉 So helpful, thank you.
    Jo

  28. Thanks for the article. I have used Catalyst / Genesis for so long that i had a brain freeze on how to add stuff to the header/footer when using a different theme. Your third solution, inserting code in the header.php is, as you point out, not recommended. I like to call those types of “solutions” time bombs. 🙂

  29. Wow, you actually put all the best and easiest ways to insert codes into a website in one place. I love Genesis method because it’s pretty straight-forward.

  30. A great helpful post as I am not a coder but being my site’s admin and I learn which thing that no developer teach me.
    Thanks and God bless to author

  31. Hi: Thanks for explaining how and where to insert the code. I am using ExactMetrics Google Analytics. I have done the above but when I go into Google Analytics – Tracking code, the fields are blank. My blog does not show up – would you perhaps know what I am missing? I do have an Analytics account (where I got the code) and it lists the correct blog site. It seems to fail when I try to connect with my gmail mail address … any input would be much appreciated.

    Thanks, Linda

  32. I kept searching regarding the head code how to customized in wordpress this article helped me a lot. You have done it in an accurate and easy answer for what I needed. Thank you.

  33. Brecht Schoeters

    You saved my day! I’ve using Genesis for most of my projects, but some projects are developed with non Genesis themes. Using Genesis solves the issue straight away, now I also have a solution for the other projects. Thanks for sharing your expertise and knowledge!

  34. I simply wanted to say thanks again. I’m not certain the things I would’ve carried out in the absence of these points provided by you regarding such field. It was before a real daunting difficulty in my view, nevertheless considering the very skilled style you treated the issue took me to jump with fulfillment. Extremely grateful for the advice and then expect you comprehend what a great job that you’re putting in training the rest all through your site. Most likely you’ve never met all of us.

  35. It is in reality a nice and helpful piece of information. I’m satisfied that you just shared this helpful info with us.

  36. Wonderful paintings! This is the kind of info that are meant to be shared around the web. Shame on the search engines for no longer positioning this submit upper! Come on over and discuss with my website . Thank you =)

  37. Thank you for all your work on this site. Gloria enjoys carrying out investigation and it’s really easy to understand why. All of us hear all about the lively mode you convey vital things through this website and cause response from others about this point then our own child is without a doubt learning a lot. Enjoy the remaining portion of the new year. You’re the one carrying out a powerful job.

  38. I want to express my appreciation to the writer just for bailing me out of this type of setting. After looking through the world wide web and getting views that were not beneficial, I assumed my entire life was well over. Existing without the presence of solutions to the difficulties you have solved all through your entire write-up is a crucial case, and ones that might have negatively damaged my entire career if I hadn’t come across your blog

  39. Thanks for every other informative web site. Where else may just I am getting that kind of information written in such an ideal way? I’ve a undertaking that I’m simply now running on, and I’ve been at the look out for such info

  40. “Some studies show the people who arising from the
    financially weaker strata are most gamble. ‘ interview with Real Colorado’s Lorne Rush – US Soccer Players.”

  41. “The other day, while I was at work, my sister stole my
    apple ipad and tested to see if it can survive a 30 foot drop, just
    so she can be a youtube sensation. My iPad is now broken and she has 83 views.
    I know this is entirely off topic but I had to share it with someone!”

  42. certainly like your website but you have to check the spelling on several of your posts. Many of them are rife with spelling problems and I to find it very bothersome to tell the reality then again I will definitely come back again

  43. Wonderful paintings! This is the kind of info that are meant to be shared around the web. Shame on the search engines for no longer positioning this submit upper! Come on over and discuss with my website . Thank you =)

  44. Real excellent information can be found on blog . “We should be eternally vigilant against attempts to check the expression of opinions that we loathe.” by Oliver Wendell Holmes.

  45. I like the helpful info you provide in your articles. I will bookmark your weblog and check again here frequently. I’m quite sure I’ll learn plenty of new stuff right here! Good luck for the next

  46. you are truly a just right webmaster. The web site loading velocity is amazing. It sort of feels that you are doing any distinctive trick. Furthermore, The contents are masterwork. you have done a great process on this subject!

  47. I simply could not leave your web site before suggesting that I extremely enjoyed the usual info an individual supply for your guests? Is gonna be back steadily to check out new posts.

  48. Hi, I love the thought of blazing new trails for Him and moving forward from out mistakes. We can use them as tools to learn from, or we can let guilt keep us in a rut. I choose to blaze forward. Thanks for the inspiration.

  49. I believe you have remarked some very interesting points, thanks for the post.
    I have read so much content about blogger lovers but this article is truly a good article, keep it up 4/20
    .

  50. My brother suggested I would possibly like this website.
    He used to be entirely right. This submit actually made my day.
    You cann’t consider just how so much time I had
    spent for this information! Thanks!

  51. Your way of delivering content is amazing and appreciable. Hope you will continue this and provide new, unique, and strong content from your side

  52. The Lottery is the Game of Luck; if your luck supports you, you can win in a single day. If your predictions go right then, you can win. Predicting the correct numbers is the main aim of Lottery. You can learn how to play the Lottery and predict the valid Hot and Cold number that increases the winning chance. Visit 49s.club to Learn all about Lottery.

  53. Excellent instructions. I do not like to use plugins if I don’t have too. It was easy to locate the theme header and head section to paste the one line of code that Pinterest needs to track. Thanks!

  54. This helped me so much! I really appreciate the time it took to provide such helpful info! I used the Insert Headers and Footers WordPress Plugin…. Took 5 seconds to add code.

  55. Hello there, just became alert to your blog through Google, and found that it is truly informative. I am gonna watch out for brussels. I’ll be grateful if you continue this in future. Lots of people will be benefited from your writing. Cheers!

  56. I’m not sure exactly why but this web site is loading extremely slow for me. Is anyone else having this problem or is it a issue on my end I’ll check back later and see if the problem still exists.

  57. I have been absent for some time, but now I remember why I used to love this site. Thank you, I¡¦ll try and check back more often. How frequently you update your website?

  58. You’ve made some good points there. I checked on the net for more info about the issue and found most people will go along with your views on this web site.

  59. Hello There. I found your blog using msn. This is a really well written article. I will make sure to bookmark it and come back to read more of your useful information. Thanks for the post. I’ll certainly return.

  60. Hello my family member! I want to say that this article is awesome, great written and include almost all important infos. I would like to see more posts like this.

  61. It can replace your Google Rank checker tool.
    It can help you Monitor your Page Seed Analytics.
    Care about Light House Metrics? – Its provides LightHouse moitor too.
    It can also do W3C Monitoring to help you fix the W3C compatibility errors
    It also gives you Website Analysis
    The best part is that all of this in a Single Dashboard.

  62. Gosloto 4/20 is also known as Stoloto 4/20. You can purchase tickets in Russia. If you are from South Africa or other sides of the world, you can participate online.

  63. As soon as I noticed this website I went on Reddit to share some of my love with them
    Some really choice blog posts on this website saved to my bookmarks.

  64. Hello,

    I’m not sure exactly why but this web site is loading extremely slow for me. Is anyone else having this problem or is it a issue on my end I’ll check back later and see if the problem still exists.

    Thanks!

  65. Great Share,
    Thanks a lot for sharing your post. It’s really amazing & helpful too. I like the way you represents everything. By sharing this amazing content, you have solved my outfit problem. Keep sharing. 🙂

    Keep it up and share you post with us.

    Thanks & Regards!
    Manu.

  66. really weird but really interesting concept. I like the fact that this is such a wild and crazy plot, but it actually subtly connects back to a lot of themes which run throughout Greek mythology

  67. I love what you guys are usually up too. This sort of clever work and reporting! Keep up the excellent works guys I’ve added you guys to my personal blogroll.

  68. uk49s results lotto is world famous lotto game. This lotto game is very interesting and amazing lottery game for gamblers. UK49s results are drawn twice in a day. Draws are held 7 days in a week.

  69. Wow! I made it to the bottom of the post and comments 🙂 This is my first comment, and I read the post through, though it took two days. Lots of links to check out.
    So much to learn. Thank you for being open and personable and teaching us how it is to be done! I’m hoping my comment posts, as I’m one of those WordPress people.

  70. Wow, wonderful weblog format! How long have you been blogging for? you make blogging look easy. The total look of your site is magnificent, let alone the content material!

  71. I have counted on blog commenting to be toughest if done intentionally by a blogger or anybody else. Blog commenting is a creative reply, query, or a simple appreciation to what we read and is resultant quotient. Curating this good habit of blog commenting is essential. What I want to mention here is I got to have great information from your blog and I am always a follower from the moment I started blogging, frankly a couple of days back only. Keep teaching us. Thanks

  72. The Lottery is the Game of Luck; if your luck supports you, you can win in a single day. If your predictions go right then, you can win. Predicting the correct numbers is the main aim of the Lottery. You can learn how to play the Lottery and predict the valid Hot and Cold number that increases the winning chance. Visit lunchtimeresults.co.za to Learn all about Lottery.

Comments are closed.