How to Add Code to Your WordPress Header
If you build a website on WordPress then you’ve probably been asked to add code snippets to your site’s header. There are lots of web services that request this, including:
- Google Analytics
- Google Adsense
- Google Search Console
- Facebook pixels
- Online advertising tools
In this post, we’ll show you how to add code to your site’s header.
What Is a Header?
When you are told to add a code snippet to your header, what this really means is to add it to your site’s HTML head. This section starts with the <head> tag and ends with </head>.
The code between these head tags includes a lot of instructions about your site. It includes the title of your page, your meta description, a link to your CSS and other instructions that help the web browser render your site.
Your site’s content begins after the closing </head> tag.
Inserting Code in the Header Manually
You can insert code snippets in your header yourself if you are technically inclined.
Within your WordPress dashboard, go to Appearance > Editor
You will look for a file named header.php and insert the code snippet in it.
This can also be done by downloading the file via FTP, editing it, and re-uploading it.
Be sure to make this change in a child theme if you use a framework.
Word of warning: whenever you edit code in the Editor, you’re modifying the theme itself. Be sure you have a current backup of your site in case anything goes wrong. If you make a mistake while editing the files manually, you might end up taking your site down.
Inserting Code Using a Plugin
For most people, it’s better to use a plugin than to edit the files yourself.
There are a lot of plugins for adding code to your site’s header. Choose one that lets you add HTML to your header.
Head, Footer and Post Injections is a popular plugin with over 100,000 active installations. Once activated, the plugin lets you easily add code to your header on all pages or select pages.
Most of these plugins also help add code into a site’s footer.
Harness the Power of WordPress
The flexibility of WordPress has helped make it the #1 platform for building websites. There are many services that work with WordPress that require you to add code snippets to the header, and now you know how to do this.
Don’t have a WordPress site yet? Get started with Namecheap EasyWP.
I can not add AdSense code in the header. After I edit code in header and save, show error code 403. How should I do ?