返回介绍

get_custom_header()

发布于 2017-09-10 23:12:21 字数 3359 浏览 998 评论 0 收藏 0

get_custom_header()

Get the header image data.


description


返回值

(object)


源代码

File: wp-includes/theme.php

function get_custom_header() {
	global $_wp_default_headers;

	if ( is_random_header_image() ) {
		$data = _get_random_header_data();
	} else {
		$data = get_theme_mod( 'header_image_data' );
		if ( ! $data && current_theme_supports( 'custom-header', 'default-image' ) ) {
			$directory_args = array( get_template_directory_uri(), get_stylesheet_directory_uri() );
			$data = array();
			$data['url'] = $data['thumbnail_url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args );
			if ( ! empty( $_wp_default_headers ) ) {
				foreach ( (array) $_wp_default_headers as $default_header ) {
					$url = vsprintf( $default_header['url'], $directory_args );
					if ( $data['url'] == $url ) {
$data = $default_header;
$data['url'] = $url;
$data['thumbnail_url'] = vsprintf( $data['thumbnail_url'], $directory_args );
break;
					}
				}
			}
		}
	}

	$default = array(
		'url'           => '',
		'thumbnail_url' => '',
		'width'         => get_theme_support( 'custom-header', 'width' ),
		'height'        => get_theme_support( 'custom-header', 'height' ),
		'video'         => get_theme_support( 'custom-header', 'video' ),
	);
	return (object) wp_parse_args( $data, $default );
}

更新日志

Versiondescription
3.4.0Introduced.

相关函数

Uses

  • wp-includes/theme.php: current_theme_supports()
  • wp-includes/theme.php: get_theme_support()
  • wp-includes/theme.php: is_random_header_image()
  • wp-includes/theme.php: _get_random_header_data()
  • wp-includes/theme.php: get_theme_mod()
  • wp-includes/theme.php: get_template_directory_uri()
  • wp-includes/theme.php: get_stylesheet_directory_uri()
  • wp-includes/functions.php: wp_parse_args()
  • Show 3 more uses Hide more uses

Used By

  • wp-includes/theme.php: get_header_video_settings()
  • wp-includes/theme.php: get_header_image_tag()
  • wp-admin/custom-header.php: Custom_Image_Header::step_1()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by schrapel

    If you want to get the custom header with a different image size use the function get_custom_header() instead of get_header_image() as the returned object has an attachment_id value.

    
    $custom_header = get_custom_header();
    if ( ! empty( $custom_header->attachment_id ) ) {
    	$image = wp_get_attachment_image_url( $custom_header->attachment_id, 'image-size' );
    }
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文