Different header files for different pages in WP

October 9, 2020

How to create different header files for different pages in WordPress.

You want to create different header file for the Home page and 404 error page.

You can use the following code

<?php
if ( is_home() ) :
    get_header( 'home' );
elseif ( is_404() ) :
    get_header( '404' );
else :
    get_header();
endif;
?>

The file names for the home and 404 headers should be header-home.php and header-404.php respectively