Get_header () is used to obtain the header function in WordPress development. wordpressheader_PHP tutorial

Source: Internet
Author: User
The following describes how to use get_header () in WordPress development to obtain the header function: wordpressheader. For more information, see get_header () in WordPress development. For more information about the meaning of the wordpressheader function, call the header. php file from the current topic. Is it easy? Well, if you want to explain how to use get_header () in WordPress development to obtain the header function, wordpressheader

Function meanings
Call the header. php file from the current topic. Is it easy? Well, if you are a newbie, please note that the get here is slightly different from the get in get_children () and get_category.

Get_header function declaration (definition)
I wrote a few articles in my previous articles and wrote code for function definition. later I found that this habit was not very good. so I decided that as long as the length permits, I would post the function topic so that I could easily look at it myself.
The location of the get_header function, declared (defined), is around 24th-36 rows in 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 will be removed in a future release if ('' == locate_template($templates, true)) load_template( ABSPATH . WPINC . '/theme-compat/header.php');}

Use of the get_header function

<?php get_header( $name ); ?>

It is very simple. from the above function declaration, we can also see that this function only accepts one variable as the parameter.

Parameter description
$ Name, as shown in the preceding function declaration, $ name is a string variable used to call 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" errors (this file should be included in your topic, named 404.php)

<?php get_header(); ?>Error 404 - Not Found<?php get_sidebar(); ?><?php get_footer(); ?>

2. multiple headers

Display 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.

Articles you may be interested in:
  • How to introduce a template file for WordPress topic creation
  • Get the header template and the bottom template in WordPress topic writing
  • PHP code instance for page number navigation added to the article list page in a WordPress topic
  • Enable theme support gadgets and add plug-ins in WordPress
  • PHP script for implementing the WordPress topic sidebar switch function
  • Write a PHP script to enable the WordPress topic to support the Widget sidebar.
  • Implementation steps for wordpress-based theme creation
  • Wordpress themes support customizing menus and modifying css styles

Retrieve () is used to obtain the header function. the wordpressheader function is used to call the header. php file from the current topic. Is it easy? Okay, if you are...

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.