Skip to content
What is the HTML for Header in WordPress
How To

What is the HTML for Header in WordPress?

· · 5 min read

The header is one of the first things a visitor sees on a WordPress site, and it does more work than it looks like – branding, navigation, sometimes a search bar or social links, all in one consistent block that appears on every page. In WordPress, the header’s HTML comes from your theme, but you still have real control over it. Here’s what that structure looks like and how you can modify it.

What is a Header in WordPress?

In WordPress, the header is the top section of a website and often appears consistently across all pages. It serves as an anchor point for branding (like a logo), navigational links, and other interactive elements. The HTML structure of a WordPress header is defined primarily by the theme you’re using, although WordPress provides flexibility in customization.

The header’s appearance can be customized via the WordPress Customizer, while its structure is controlled by the header.php template file found within the theme folder.

Also Read: How to Create Coupons on WordPress Products

HTML Structure for Header in WordPress

The header in WordPress follows a typical HTML structure that defines how its content is displayed. A common example of the basic HTML structure for a header might look like this:

<header id="masthead" class="site-header" role="banner">
  <div class="site-branding">
    <a href="<?php echo esc_url(home_url('/')); ?>" rel="home">
      <img src="<?php echo get_template_directory_uri(); ?>/images/logo.png" alt="Site Logo">
    </a>
    <h1 class="site-title"><?php bloginfo('name'); ?></h1>
  </div><!-- .site-branding -->

  <nav id="site-navigation" class="main-navigation" role="navigation">
    <?php wp_nav_menu(array('theme_location' => 'primary')); ?>
  </nav><!-- #site-navigation -->

  <div class="header-widget-area">
    <?php dynamic_sidebar('header-widget'); ?>
  </div><!-- .header-widget-area -->
</header><!-- #masthead -->

This structure can vary depending on the theme but generally includes the following key elements:

  • A header tag to define the header section.
  • site-branding for logo or site title.
  • nav element to hold the navigation menu.
  • Optional widget areas.

Understanding header.php

The header.php file in your WordPress theme is the main template file responsible for rendering the header on your website. Located in the theme folder (e.g., wp-content/themes/your-theme/header.php), this file contains the HTML structure and PHP code that displays the header.

The typical header.php file starts with the document type declaration and includes WordPress functions that ensure the proper loading of styles, scripts, and metadata. Below is a simplified version:

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<header>
<div class="header-inner">
<h1><?php bloginfo('name'); ?></h1>
<nav>
<?php wp_nav_menu(array('theme_location' => 'header-menu')); ?>
</nav>
</div>
</header>

Elements of a WordPress Header

Logo and Site Title

One of the most common elements of a WordPress header is the logo or site title. The HTML for this is often wrapped in a <div> tag and placed inside the header. WordPress themes typically offer options to upload a custom logo or choose to display the site title in text form.

<div class="site-branding">
<a href="<?php echo esc_url(home_url('/')); ?>">
<img src="<?php echo get_template_directory_uri(); ?>/images/logo.png" alt="Site Logo">
</a>
<h1><?php bloginfo('name'); ?></h1>
</div>

Navigation Menu

Another essential component is the navigation menu, which helps visitors explore the site. WordPress uses the wp_nav_menu() function to generate the navigation dynamically. The HTML for the navigation menu is typically placed inside a nav tag.

<nav id="site-navigation" class="main-navigation">
<?php wp_nav_menu(array('theme_location' => 'primary')); ?>
</nav>

Social Icons and Search Bar

Some headers also feature social media icons or a search bar. These elements are often added through WordPress widgets or hardcoded directly into the header.php file.

<div class="header-widget-area">
<?php dynamic_sidebar('header-widget'); ?>
</div>

Also Read: How to Restore WordPress Category

How to Customize Header HTML in WordPress

Using the WordPress Customizer

The WordPress Customizer provides a user-friendly interface for editing the header without touching any code. You can:

  • Change the logo or site title.
  • Customize the navigation menu.
  • Add widgets like a search bar or social media icons.

To access the Customizer:

  1. Go to Appearance > Customize in your WordPress dashboard.
  2. Look for options labeled Header or Site Identity to modify the logo, title, and more.

Directly Editing the header.php File

For more advanced customization, you can directly edit the header.php file. This allows you to add or remove HTML elements, such as additional navigation menus or custom widgets.

To edit:

  1. Navigate to Appearance > Theme Editor.
  2. Choose the header.php file from the list on the right.
  3. Make your changes and click Update File.

SEO and Accessibility in Header Design

When customizing the HTML for your header, it’s worth considering both SEO and accessibility. Here are a few tips:

  • SEO: Use semantic HTML tags like <header>, <nav>, and <h1> to provide structure and meaning. Ensure that your logo has an alt tag to describe the image.
  • Accessibility: Include ARIA attributes such as role="banner" for the header and role="navigation" for the navigation bar. This makes the site easier to navigate for screen readers and users with disabilities.

Here’s an example of a semantic and accessible header structure:

<header role="banner">
<div class="site-branding">
<a href="/" aria-label="Home">
<img src="/logo.png" alt="Site Logo">
</a>
<h1><?php bloginfo('name'); ?></h1>
</div>
<nav role="navigation" aria-label="Main Navigation">
<?php wp_nav_menu(array('theme_location' => 'primary')); ?>
</nav>
</header>

Building a Header That Works

The header is a small piece of markup that carries a lot of weight – it houses your logo, navigation, and often the first impression a visitor gets. Once you understand how header.php builds that structure, you can customize it confidently, whether through the Customizer or by editing the template directly, without breaking your site’s SEO or accessibility along the way.

Interesting Reads:

What Is the Best Tool to Scan WordPress Site?

Top Professional Health & Fitness WordPress themes

Best Travel WordPress Themes