WordPress load header template tag: get_ header

WordPress template tag get_ The header is used to load the header template header.php

get_header( string $name = null )

get_ The header tag is loaded by default header.php , but you can load a similar header by passing a parameter- name.php Template for:

<?php get_header('name'); ?>

The above example loads the header- name.php Template, if header- name.php If the file does not exist, it will be loaded header.php In this way, there is no header- name.php An alternative option is provided for the file.

We can use page judgment to load different header templates for different pages

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

The above example loads the header for the home page- home.php , load header-404.php for 404 pages, and load other pages header.php

We can also load different header templates for categories and tabs:

<?php
if ( is_category() ) :
	get_header( 'category' );
elseif ( is_tag() ) :
	get_header( 'tag' );
else :
	get_header();
endif;
?>

The above example loads the header for the classification page- category.php To load the header for the tab- tag.php

If you master the usage of WordPress conditional tags, you can give full play to your imagination and customize the personalized theme.

Extended reading

get_ The header() function is located in: WP includes / general- template.php

Related Tags:

  • get_ sidebar()
  • get_ template_ part()
  • get_ search_ form()
  • comments_ template()
  • get_ footer()
Related Article
WordPress comment date tag: comment_date

WordPress template tags comment_ Date is used to output the date of a comment, usually in a custom comment template. Read more

WordPress comment summary tag: comment_excerpt

WordPress template tags comment_ Excerpt is used to output the summary of comments. The default output is 20 characters. It Read more

WordPress comment time tag: comment_time

WordPress template tags comment_ Time is used to output the publishing time of the current comment, which is the same Read more

WordPress RSS format comment author name tag: comment_author_rss

WordPress template tags comment_ author_ RSS is used to output the comment author name in RSS format, which has no Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image