The usage of Get_header function in the development of WordPress

Source: Internet
Author: User
Explanation of function meaning
Invokes the header.php file from the current topic. Isn't it simple? Well, if you're a novice, here's a reminder that get and Get_children () and get_category get slightly different here.

get_header function declaration (definition)
Before writing the article rarely write the code of the function definition, and later found that the habit is not very good, so decided, as long as the space allows, will be the function of the theme paste out, to facilitate their own look.
The position of the Get_header function, declared (defined), is the position around the 24–36 line of the wp=include/general-template.php file.

function Get_header ($name = null) {do_action (' Get_header ', $name);  $templates = Array (); if (Isset ($name)) $templates [] = "header-{$name}.php";  $templates [] = ' header.php ';  Backward Compat code would be removed in a future release if (' = = = Locate_template ($templates, True)) Load_template (AB spath. Wpinc. '/theme-compat/header.php ');}

Use of the Get_header function

<?php Get_header ($name);?>

Very simply, from the function declaration above we can see that the function only accepts a variable as a parameter.

Parameter interpretation
$name, as we can see from the function declaration above, $name is a string variable used to invoke the alias template of the header.
For example $name = "AB";
That's what we do.

<?php   $name = "AB"  Get_header ($name);  ? >

This will call the header-ab.php file as the header file.

Example:

1. Simple 404 page

The following code is a simple template file, specifically used to display "HTTP 404:not Found" error (this file should be included in your theme, named 404.php)

<?php Get_header ();?>

Error 404-not Found

<?php Get_sidebar (); ><?php get_footer ();?>

2. Multiple head

Show different headers for different pages

<?phpif (Is_home ()): Get_header (' home '); ElseIf (is_404 ()): Get_header (' 404 '); Else:get_header (); endif;? >

These headers for home and 404 should be named header-home.php and header-404.php, respectively.

The above describes the introduction of the WordPress development in the use of Get_header function, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.