


Analysis of related PHP functions of custom headers in WordPress theme production, wordpress is being produced_PHP tutorial
Related PHP function analysis of custom headers in WordPress theme production, WordPress production
header_image()
The header_image() function is the standard interface function for WordPress to customize the top image. This function can automatically determine the background settings and return the user-defined top image address in the form of a string. This article mainly involves the detailed explanation and use of this function.
【Display header image path.】 That is, display the top image address.
Use
Copy code The code is as follows:
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 header
The get_custom_header function is a new gift given to us by WordPress 3.4. This function appears to better integrate and encapsulate the use of the top. This article mainly explains the get_custom_header function in detail and how to integrate it in the WordPress 3.4 version theme. Top features.
Please note that when using your theme according to this article, please make sure that your WordPress has been upgraded to version 3.4.
Detailed explanation of the meaning of get_custom_header
Customizing the top At present, most themes mainly use two functions: 1. Customize the top image 2. Customize the top style
For specific effects, you can take a look at the default theme twenty eleven, or my other blog Youyou My Heart
This function is a built-in function that only appeared in WP version 3.4. It is mainly used to return the top parameters set by the user in the form of objects.
Maybe you still don’t understand just by saying such nonsense. If you want to understand, please read below.
Please note that this function is fundamentally different from get_header().
Function usage examples
The following example comes from the header.php file
in the default theme twenty eleven
PHP code:
//判断是否存在该函数,以便兼容老版本 if ( function_exists( 'get_custom_header' ) ) { //get_custom_header()->width 调用带向 width 属性 $header_image_width = get_custom_header()->width; //get_custom_header()->height 调用带向 height 属性 $header_image_height = get_custom_header()->height; } else {//兼容老版本的代码 $header_image_width = HEADER_IMAGE_WIDTH; $header_image_height = HEADER_IMAGE_HEIGHT; }
Detailed explanation of comprehensive use
The following mainly quotes official documents to explain custom top
//打开主题自定义顶部支持 add_theme_support( 'custom-header' ); $headarg = array(//将设置打包成数组 '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_theme_support( 'custom-header', $headarg );
Custom top image
//打开主题自定义顶部支持 add_theme_support( 'custom-header' ); $headarg = array(//将设置打包成数组 '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_theme_support( 'custom-header', $headarg );
Adaptive top image settings
$args = array( 'flex-width' => true,//自适应高度 'width' => 980, 'flex-width' => true,//自适应宽度 'height' => 200, 'default-image' => get_template_directory_uri() . '/images/header.jpg', ); add_theme_support( 'custom-header', $args );
Call of custom top image
<img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
Articles you may be interested in:
- How to introduce template files in WordPress theme production
- Get the header template and bottom template in WordPress theme writing
- Example of PHP code for adding page number navigation to article list page in WordPress theme
- Enable theme to support widgets and add plug-in enabling function in WordPress
- PHP script to implement WordPress theme sidebar switching function Detailed explanation
- Write PHP script to make WordPress theme support Widget sidebar
- Specific implementation steps based on wordpress theme production
- Wordpress theme supports custom menu and modified css style implementation Method

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft