How does get_header() get the header.php template? – Detailed PHP
-
I am currently writing about WordPress and wanted to explain how the get_header() function worked. But then I hit a dead end.
The get_header function looks like this:
function get_header( $name = null ) { do_action( 'get_header', $name ); $templates = array(); if ( isset($name) ) $templates[] = "header-{$name}.php"; $templates[] = "header.php"; if ('' == locate_template($templates, true)) load_template( get_theme_root() . '/default/header.php'); }I figured out that $templates is an array in which the filename “header.php” ( and header-($name).php – if $name is set) is stored.
After that $template is added to the function
locate_template()which searches for the given file, and returns a string containing the file path if one is found or an empty string if no file is found.If the string is empty the default header is loaded through
load_template().Now to the dead end. I cant seem to figure out where the template file is being loaded. It’s like there is an “else” missing in the “if” sentence. eg.
if ('' == locate_template($templates, true)) load_template( get_theme_root() . '/default/header.php'); else $template = locate_template($templates, true); load_template($template);The only other option i could think of would be that the template was loaded in
do_action('get_header', $name);
but i havn’t been able to find anything of the like in the source codes. So if anyone knows anything about this, please help(the sooner the better).Thanks in advance.
The topic ‘How does get_header() get the header.php template? – Detailed PHP’ is closed to new replies.