Setup & site building · Guide
How to Add Code to the WordPress Header and Footer

Short answer
Add code to the WordPress header and footer with WPCode: install it, open Code Snippets, then Header and Footer, paste the snippet into the Header, Body or Footer field, and click Save Changes. Header code prints inside the head element, and footer code prints just above the closing body tag.
Key takeaways
- WordPress has no built-in header and footer code screen; WPCode and similar plugins fill that gap.
- wp_head() goes at the end of the head element in header.php, and wp_footer() just before the closing body tag.
- In WPCode, Header code prints in the head, Body code just below the opening body tag, and Footer code above the closing body tag.
- WP Headers and Footers 3.2.0 was released 19 October 2026 and is compatible with WordPress 7.1.
- Removing a verification tag can unverify your site with that service.
What code goes in the header and footer?
The header holds code that must load early, such as verification meta tags and analytics, while the footer holds code that can load last, such as chat widgets and tracking pixels.
“Header code” means code inside the HTML <head> element, not the visible header at the top of the page. “Footer code” means code just before the closing </body> tag at the end of the page.
WordPress has no built-in screen for adding this code, so the usual routes are a plugin such as WPCode or edits to a child theme. WPCode states that WordPress has no built-in way to add code to the header or footer, and that its header and footer fields fill that gap, as explained on WPCode.
Common examples are a Google Analytics tag, a Facebook Pixel, a Search Console verification tag, a chat widget and custom CSS. Each provider tells you where its snippet belongs, so follow those instructions first.
How does WordPress place header and footer code?
Themes print header code through the wp_head hook and footer code through the wp_footer hook, which plugins use to add their own code.
The Theme Handbook's plugin API hooks page states that wp_head() goes at the end of the <head> element in the theme's header.php file, and wp_footer() goes in footer.php, just before the closing </body> tag. A third hook, wp_body_open(), goes at the start of the <body> element.
Because plugins hook into these same points, a plugin can add your code without you editing any theme file. That is why the plugin route survives theme updates while direct file edits do not.
Block themes work the same way from your side of the screen: the blocks that build the page already support the relevant hooks, as noted in Learn WordPress's plugin API hooks lesson. You still add the code through a plugin, not through a template file.
How do you add header and footer code with WPCode?
Install WPCode, open Code Snippets, then Header and Footer, paste each snippet into its field, and click Save Changes.
Follow these steps:
- Go to Plugins, then Add New, search for WPCode, and install and activate it.
- Go to Code Snippets, then Header and Footer.
- Paste the snippet for the head into the Header field.
- Paste the snippet for the body into the Body field, if your provider gave you one.
- Paste the snippet for the end of the page into the Footer field.
- Click Save Changes.
WPCode's global header and footer docs state that anything in the Header field is printed in the <head> section of every page, Body code is printed just below the opening <body> tag, and Footer code is printed just above the closing </body> tag. Leave a field blank if you have nothing for it.
Paste each snippet exactly as the provider gave it, including its opening and closing <script> tags. WPCode prints the field contents as they are, so a snippet without its tags will show up as plain text on your pages.
How do you add header and footer code without WPCode?
Use the free WP Headers and Footers plugin, which gives you Header, Body and Footer fields under Settings.
The plugin's WordPress.org page says it inserts code into the header, body and footer areas without editing theme files, and lists Google Analytics code, Facebook Pixel code, Search Console verification code and custom CSS among its uses. Version 3.2.0 was released on 19 October 2026 and is compatible with WordPress 7.1.
Install it from Plugins, then Add New, then open Settings, then WP Headers and Footers, and paste your code into the matching field. The steps are the same idea as WPCode, with fewer extra features.
Pick one header and footer plugin and use it for all your snippets. Two plugins doing the same job can print the same tracking code twice, which double-counts your visitors.
How do you add header or footer code with a child theme?
Add the code to the child theme's header.php or footer.php file, or hook it in from the child theme's functions.php with wp_head or wp_footer.
Editing the parent theme's files is the method to avoid, since the next theme update replaces them. A child theme keeps your edits, as explained in the guide to what a child theme is.
The hook method looks like this in the child theme's functions.php:
add_action( 'wp_head', 'mysite_add_header_code' );
function mysite_add_header_code() {
echo '<meta name="example-verification" content="abc123">';
}
This route suits developers who already work in theme files. For most site owners, the plugin route is faster and easier to undo, since each snippet has its own on and off switch.
If your theme is a block theme, there is no header.php file to edit. Use a plugin instead, or edit the header template part in the Site Editor; the guide to editing the header in a block theme covers the template route.
Where does each type of code go?
Verification tags and CSS go in the header, tag manager containers go in the header and body, and analytics, pixels and chat widgets usually go in the footer.
| Code | Where it goes | Why |
|---|---|---|
| Search Console verification meta tag | Header | Google reads it from the page head |
| Google Analytics tag | Header or footer | Follow the provider's instructions |
| Tag manager container | Header and body | Needs a snippet in both places |
| Facebook Pixel | Header or footer | Loads after the page content is fine |
| Chat widget | Footer | Loads last so it cannot slow the page |
| Custom CSS | Header | Styles must load before the page is drawn |
| Verification or meta tags | Header | Meta tags belong in the head |
Google's site ownership verification page lists the HTML tag method as relatively simple, but notes that it requires the ability to edit the HTML source of your site's home page. If your provider gives no location, WPCode's docs advise that the header is the safest choice.
Never paste PHP into a header or footer field meant for HTML, CSS or JavaScript. Those fields print their contents as they are, and PHP code in them will show up as text on your pages instead of running.
How do you check the code is working?
Open a page in a private browser window, view the page source, and search for a unique part of your snippet.
WPCode's global header and footer docs state that header code appears near the top inside the <head> section, body code appears just after the opening <body> tag, and footer code appears near the very bottom. Search the source for those spots.
Then check the service itself: Search Console should show the site as verified, and your analytics account should start receiving visits. Clear any page cache first, since a cached page may still show the old version without your code.
If the code is missing from the source, check that the snippet is switched on and that its location is set to the whole site rather than one page. Also check that no caching plugin is serving an old copy.
The guide to setting up a staging site for WordPress is a good place to test a new snippet before it goes live.
How do you remove header or footer code?
Delete the snippet from the field where you added it, save, and clear the cache so visitors stop receiving the old code.
In WPCode, open Code Snippets, then Header and Footer, clear the field, and click Save Changes. For a single snippet made with WPCode's snippet editor, switch that snippet off or delete it from the Snippets list.
If the code was added in a child theme file, remove it from that file and save. If it was added to the parent theme, move any code you still need to a plugin first, since the next theme update will remove it anyway.
Removing a verification tag can unverify your site with that service, as Google notes on its site ownership verification page. Keep the tag in place while you still use the service.
What mistakes should you avoid?
Do not paste the same tracking code twice, do not edit the parent theme's files, and do not paste a snippet without its script tags.
Two copies of an analytics tag double-count visits, and two pixels can fire duplicate events. Use one plugin for header and footer code, and check the page source after you add a new snippet to confirm it appears once.
Other mistakes to avoid:
- Pasting a snippet into the wrong field, such as footer code into the header.
- Adding code from a source you do not trust, since header code runs on every page.
- Forgetting to save, since WPCode's Save Changes button sits at the top right of the page.
- Leaving old verification tags in place after you stop using a service.
Before you add any code, note what it is for, where it goes, and how you will remove it. A header full of forgotten snippets slows the site and makes the next cleanup harder.
The guide to adding security headers to WordPress covers a related kind of header change that is often confused with adding code to the head.
Frequently asked questions
Does WordPress have a built-in way to add header code?
No. WordPress has no built-in screen for header and footer code. Use a plugin such as WPCode or the free WP Headers and Footers plugin, or add the code to a child theme. Never edit the parent theme's header.php or footer.php files.
Where does WPCode put header and footer code?
Header code prints inside the head element of every page, body code prints just below the opening body tag, and footer code prints just above the closing body tag. Paste each snippet exactly as the provider gave it, including its script tags.
What code goes in the header and what goes in the footer?
Verification meta tags and CSS go in the header. Analytics tags go in the header or footer, as the provider directs. Tag manager containers need a snippet in both the header and the body. Chat widgets usually go in the footer so they load last.
How do I check my header code is working?
Open a page in a private browser window, view the page source, and search for a unique part of your snippet. Header code should appear near the top inside the head section, and footer code near the very bottom. Clear any page cache first.
How do I remove code from the header or footer?
Delete the snippet from the field where you added it, save, and clear the cache. For a WPCode snippet, switch it off or delete it from the Snippets list. Removing a verification tag can unverify your site with that service.
Sources
- Using the Global Header & Footer settings WPCode
- Plugin API Hooks WordPress Developer Resources
- Insert Headers And Footers WordPress.org
- Verify your site ownership Google Search Central
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
Related guides
About the editors
Researched from the primary sources listed above and checked against our editorial rules before publishing.


