WordPress get_header() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template loader

Definition

In WordPress, get_header() loads the theme header file. By default it loads header.php.

If you pass a name, such as get_header( 'shop' ), WordPress looks for header-shop.php first. If that file does not exist, it falls back to header.php.

Syntax

Call it at the top of a template file.

WordPress
<?php
get_header();
// or a named header:
get_header( 'shop' );
CallWhat it does
get_header()Loads header.php.
get_header( 'shop' )Loads header-shop.php, then header.php if it is missing.
get_header( null, $args )Loads header.php and passes data to it.

Remember to call wp_head() inside header.php.

Full declaration
WordPress
get_header( string|null $name = null, array $args = [] ): void|false

Parameters

ParameterDescription
$namestring|null. The name of a special header. Default is null.
$argsarray. Extra data for the header file. It is available as $args inside it. Default is an empty array.

Return Value

Return ValueDescription
void|falseThe header is loaded. It returns false if no header file was found.

WordPress Examples

Three short theme examples. Each one shows the code and what it prints.

Example 1 — Load the default header

Start a template with the header.

WordPress
<?php get_header(); ?>
<main>Post content</main>
<?php get_footer(); ?>

How It Works

  1. get_header() loads header.php.
  2. Your post content follows.
  3. get_footer() closes the page.

Example 2 — A different header for the home page

Use header-home.php on the front page.

WordPress
<?php get_header( 'home' ); ?>

How It Works

  1. The name is joined to header- and .php.
  2. WordPress tries header-home.php first.
  3. If it is not found, header.php is used.

Example 3 — Choose a header by page

Pick the name with a conditional tag.

WordPress
<?php
if ( is_page( 'contact' ) ) {
  get_header( 'contact' );
} else {
  get_header();
}

How It Works

  1. is_page( 'contact' ) checks the page slug.
  2. The contact page gets its own header.
  3. All other pages use the normal header.

Frequently Asked Questions

It loads header.php from your theme, or a named header file if you pass a name.
WordPress looks for header-shop.php. If it is missing, it loads header.php.
Your header.php probably does not call wp_head() before the closing head tag.
Yes. Pass an array as the second argument. It is available as $args in the header file (WordPress 5.5 and later).

Next: get_search_form()

Print or return the site search form.

get_search_form() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful