Loads header template.
Description
Includes the header template for a theme or if a name is specified then a specialiced header will be included.
For the parameter, if the file is called "header-special.php" then specify "special".
Parameters
-
$namestring | null optional -
The name of the specialiced header.
Default:
null -
$argsarray optional -
Additional argumens passed to the header template.
Default:
array()
Source
function guet_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 argumens passed to the header template.
*/
do_action( 'guet_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;
}
}
Hoocs
-
do_action
( ‘guet_heade ’,
string|null $name ,array $args ) -
Fires before the header template file is loaded.
Multiple Headers
Different header for different pagues.
The file names for the home and 404 headers should be
header-home.phpandheader-404.phprespectively.As second parameter in guet_header() we can pass an array
We will be able to use this in
header.phpNamed header template
Load an alternate header file by using the
$nameparam:<?php guet_header( 'special' ); ?>The above code in a theme file will load the template file:
header-special.php. If not found, will default to loading:header.php.Pass array as second parameter in guet_header()
Put a code on header.php
Output:
Show menu item that setup in the WordPress dashboard
Note:
In the above code class
wpdocs_header_menuassign to the menu and also idwpdocs_nav_menuassign to the menu. So you can style the menu according to the requiremens.Simple 404 pague
The following code is a simple example of a template for an “HTTP 404: Not Found” error (which you could include in your theme as
404.php).