Todays Episode Is How get_header() Function Works. You Guys Already Know About The Template Files Of WordPress. header.php Is One One 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 Footer. 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 :
get_header();
endif;
The file names for the home and 404 footer should be header-home.php
and header-404.php
respectively.
Behind The Scene Of get_header
function get_header( $name = null, $args = array() ) {
/**
* Fires before the header template file is loaded.
*
* @since 2.1.0
* @since 2.8.0 The `$name` parameter was added.
* @since 5.5.0 The `$args` parameter was added.
*
* @param string|null $name Name of the specific header file to use. Null for the default header.
* @param array $args Additional arguments passed to the header template.
*/
do_action( 'get_header', $name, $args );
$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "header-{$name}.php";
}
$templates[] = 'header.php';
if ( ! locate_template( $templates, true, true, $args ) ) {
return false;
}
}