A custom header-related PHP function parsing _php technique in WordPress theme making

Source: Internet
Author: User

Header_image ()
the Header_image () function is the standard interface function of the WordPress custom top image, which automatically determines the background settings and returns the user-defined top image address in the form of a string. This article mainly involves the function of the detailed and use.

"Display header image path." That is, displays the top image address.
Use

Copy Code code as follows:

"alt=" "/>

function declaration Source Code
function Header_textcolor () {
 echo get_header_textcolor ();
}
function Get_header_image () {
 $url = get_theme_mod (' Header_image ', Get_theme_support (' Custom-header ', ' Default-image '));
 
 if (' remove-header ' = = $url) return
 false;
 
 if (Is_random_header_image ())
 $url = Get_random_header_image ();
 
 if (Is_ssl ())
 $url = str_replace (' http://', ' https://', $url);
 else
 $url = str_replace (' https://', ' http://', $url);
 
 Return Esc_url_raw ($url);

Get_custom_header Custom Top
the Get_custom_header function is a new gift from WordPress 3.4, which appears in order to better integrate and encapsulate the top of the use, this article mainly on Get_custom_header This function is detailed, and how to The WordPress 3.4 version of the theme integrates the top features.

Please note that depending on your theme, please make sure that WordPress has upgraded to version 3.4.

A detailed explanation of get_custom_header meaning
Custom top most of the topics currently used are only two feature 1. Custom top image 2. Customize Top Style
The specific effect you can look at the default theme twenty eleven, or my other blog leisurely my heart
This function is a WP 3.4 version before the emergence of a built-in function, mainly for the user set the top of the parameters in the form of objects (object) returned.
Just say this nonsense, perhaps you do not understand, want to understand the words, please look down.
Please note that this function is essentially different from get_header ().

Use instances of a function
The following example comes from the default theme twenty eleven header.php file
PHP Code:

Determine if the function exists so that compatibility with the old version
if (function_exists (' Get_custom_header ')) {
//get_custom_header ()->width call to the width Property
$header _image_width = Get_custom_header ()->width;
Get_custom_header ()->height call with the Height property
$header _image_height = Get_custom_header ()->height;
} else {//compatible with the old version of the code
$header _image_width = header_image_width;
$header _image_height = header_image_height;
}

Comprehensive use of detailed
The following major quotes from the official document explain the custom top

Open topic customization Top support
add_theme_support (' Custom-header ');
 
$headarg = Array (//will be set to package the array
 of ' default-image '     => ', '
 random-default '     => false,
 ' width '         => 0,
 ' height '         => 0,
 ' flex-height '      => false,
 ' Flex-width '       => false,
 ' Default-text-color '   => ', '
 header-text '      => true,
 ' uploads '        => true,
 ' wp-head-callback '    => ', '
 admin-head-callback '  => ',
 ' admin-preview-callback ' = > ",
);
Add the settings in the array to the custom top
add_theme_support (' Custom-header ', $headarg);

Customizing the top image

Open topic customization Top support
add_theme_support (' Custom-header ');
 
$headarg = Array (//will be set to package the array
 of ' default-image '     => ', '
 random-default '     => false,
 ' width '         => 0,
 ' height '         => 0,
 ' flex-height '      => false,
 ' Flex-width '       => false,
 ' Default-text-color '   => ', '
 header-text '      => true,
 ' uploads '        => true,
 ' wp-head-callback '    => ', '
 admin-head-callback '  => ',
 ' admin-preview-callback ' = > ",
);
Add the settings in the array to the custom top
add_theme_support (' Custom-header ', $headarg);

Adaptive Top Image settings

$args = Array (
 ' flex-width '  => true,//Adaptive height
 ' width '     => 980,
 ' flex-width '  => true,//Adaptive width
 ' height '    =>,
 ' default-image ' => Get_template_directory_uri (). '/images/header.jpg ',
);
Add_theme_support (' Custom-header ', $args);

Customizing the call to the top image

height;?>" 
  width= "<?php Echo get_custom_header ()->width;?>" alt= ""/> 

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.