BackBlog / Web Design
6 min read·

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.

Preston Vawdrey

Preston Vawdrey

SEO Marketing Expert

"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.

  1. Go to Appearance > Editor.
  2. Click Patterns, then Template Parts.
  3. Select Header.
  4. Edit blocks directly, or click the three dots and choose Edit as HTML on any individual block to see its markup.
  5. 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.

  1. Create a folder in /wp-content/themes/ named something like yourtheme-child.
  2. Add a style.css with a header comment declaring Template: yourtheme.
  3. Add a functions.php that enqueues the parent stylesheet.
  4. Copy header.php from the parent theme into the child folder.
  5. 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.

Marketing that actually moves the needle

Occasional notes on SEO, paid ads, and growth, plus every new post, straight to your inbox. Written for operators, not skimmers.

No spam. Unsubscribe anytime.