函数文档

get_custom_header_markup()

💡 云策文档标注

概述

get_custom_header_markup() 函数用于获取自定义页眉的 HTML 标记,在 Customizer 预览中始终返回容器 div。

关键要点

  • 函数返回自定义页眉的标记字符串,成功时包含容器 div 和图像标签。
  • 仅在设置了自定义页眉或处于 Customizer 预览模式时返回标记,否则返回空字符串。
  • 内部使用 has_custom_header()、get_header_image_tag() 和 is_customize_preview() 函数。

代码示例

function get_custom_header_markup() {
	if ( ! has_custom_header() && ! is_customize_preview() ) {
		return '';
	}

	return sprintf(
		'%s',
		get_header_image_tag()
	);
}

注意事项

  • 该函数自 WordPress 4.7.0 版本引入。
  • 相关函数包括 the_custom_header_markup() 用于直接打印标记。

📄 原文内容

Retrieves the markup for a custom header.

Description

The container div will always be returned in the Customizer preview.

Return

string The markup for a custom header on success.

Source

function get_custom_header_markup() {
	if ( ! has_custom_header() && ! is_customize_preview() ) {
		return '';
	}

	return sprintf(
		'<div id="wp-custom-header" class="wp-custom-header">%s</div>',
		get_header_image_tag()
	);
}

Changelog

Version Description
4.7.0 Introduced.