How get_header() Function Works?

In The Previous Episode I Show You Guys Common Templates File Of WordPress. header.php Was One Of Them. For Including That header.php File Into Another File Like Index.php Just Call The Function get_header(). The Content Of The header.php Will Come In Your Index.php File Or Any Other File That You Want To Include. Not Only That, You Might Want That In Different Page Of Your Website You Want Different Header. No Matter get_header() Will Do That Job Also. get_header(string $name = null ) Its Support A Parameters Which Is Optional. Suppose You Need A Different Header In Your 404 Page Or In Your Home Page Or Any Other Page. You Can Write Like

if ( is_home() ) :
get_header( 'home' );
elseif ( is_404() ) :
get_header( '404' );
else :

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

Behind The Scene Of get_header();

function get_header( $name = null ) {
* Fires before the header template file is loaded.
* @since 2.1.0
* @since 2.8.0 $name parameter added.
* @param string|null $name Name of the specific header file to use. null for the default header.
do_action( 'get_header', $name );
$templates = array();
$name      = (string) $name;
if ( '' !== $name ) {
$templates[] = "header-{$name}.php";
$templates[] = 'header.php';
locate_template( $templates, true );
Please follow and like us:

1 thought on “How get_header() Function Works?”

Leave a Comment