^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_custom_header()用法示例

get_custom_header()

Get the header image data.


描述


返回值

(object)

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


源代码

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 );
}

更新日志

Version 描述
3.4.0 Introduced.

相关函数

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


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()

  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' );
    }
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈