How to Edit the Header HTML in WordPress: 3 Practical Methods
Where the header HTML actually lives in WordPress depends on whether you run a block theme or a classic theme. Here are three safe ways to edit it.
"Where is the header HTML in WordPress?" has three different answers, and which one applies to you depends entirely on your theme.
Editing the wrong file gets your change wiped on the next theme update. Here is where the header HTML in WordPress actually lives and how to change it without breaking anything.
First, Find Out Which Theme Type You Have
Go to Appearance in your WordPress admin.
If you see Editor, you have a block theme. Twenty Twenty-Four, Twenty Twenty-Five, and most themes released in the last few years are block themes. Your header is a template part edited visually.
If you see Customize and Theme File Editor instead, you have a classic theme. Astra, GeneratePress, Divi, and older commercial themes usually fall here. Your header lives in a PHP file.
Everything below splits along that line.
Method 1: Block Themes, Through the Site Editor
Block themes store the header as a template part you edit in the browser. No code required for most changes.
- Go to Appearance > Editor.
- Click Patterns, then Template Parts.
- Select Header.
- Edit blocks directly, or click the three dots and choose Edit as HTML on any individual block to see its markup.
- Click Save.
For raw markup that no block covers, add a Custom HTML block inside the header template part and paste your code in. That is the supported way to get literal HTML into a block theme header.
Changes here are stored in your database, not in theme files, so a theme update will not overwrite them.
Method 2: Classic Themes, Through a Child Theme
Classic themes keep the header in header.php. WordPress ships a Theme File Editor that lets you edit it directly, and you should not use it on your parent theme. The next theme update overwrites the file and your change disappears.
Use a child theme instead.
- Create a folder in
/wp-content/themes/named something likeyourtheme-child. - Add a
style.csswith a header comment declaringTemplate: yourtheme. - Add a
functions.phpthat enqueues the parent stylesheet. - Copy
header.phpfrom the parent theme into the child folder. - Edit the copy. WordPress loads the child version instead of the parent.
The WordPress child theme documentation has the exact boilerplate for steps 2 and 3.
Back up the file before you touch it. A stray unclosed tag in header.php takes the whole site down, not just the header.
Can You Edit the Header HTML Without Editing Theme Files?
Yes, and for anything script-shaped you should. Tracking pixels, verification tags, fonts, and schema markup do not belong in header.php at all. They belong on the wp_head hook.
Add this to your child theme's functions.php:
function my_custom_head_output() {
?>
<meta name="my-verification" content="abc123">
<?php
}
add_action( 'wp_head', 'my_custom_head_output' );
This survives theme updates, works on block and classic themes alike, and keeps your markup out of a file that WordPress considers the theme's property. Plugins like WPCode do the same thing with a UI if you would rather not write PHP.
What Usually Breaks
Three mistakes account for most broken headers.
Editing the parent theme instead of a child theme. Your work is gone at the next update, usually at the worst possible time.
Pasting a script into header.php above the wp_head() call. Load order matters, and scripts that run before WordPress has finished setting up the page behave unpredictably.
Forgetting to close a tag. HTML is forgiving, PHP is not, and an unclosed PHP block produces a white screen with no error message. Always keep a copy of the original file where you can restore it over FTP.
The Takeaway
Editing the header HTML in WordPress comes down to your theme type. Block themes use the Site Editor and a Custom HTML block. Classic themes use header.php inside a child theme. Scripts and meta tags belong on the wp_head hook in either case.
If you are weighing whether WordPress is still the right platform for a small business site, I wrote about that here. And if header edits are part of a bigger cleanup, my notes on saving money on WordPress web design cover what to do yourself and what to hand off.
More notes
How to Turn Off Distraction Free Mode in WordPress: 2 Simple Ways
Your WordPress toolbars vanished and you cannot get them back. That is Distraction Free mode. Here are the two ways to switch it off in about three seconds.
Web DesignHow to Add a Navigation Bar in WordPress: A Practical Guide
Adding a navigation bar in WordPress works one way on block themes and a completely different way on classic themes. Here is both, plus what to put in it.
Web DesignHow to Scan WordPress for Vulnerabilities: 4 Tools That Work
Most WordPress sites get hacked through a plugin nobody updated. Here are four ways to scan WordPress for vulnerabilities, from a free URL check to a real audit.
Web DesignVibe Coding a Headless WordPress Migration: From Vite SPA to Next.js + Vercel + SiteGround
How GLM 5.2 and opencode handled a security pass and a three-domain headless WordPress migration plan for Draftly.blog in a single AI session.
