1. 主页
  2. 文档
  3. WordPress函数
  4. add_theme_support
  5. Custom Header

Custom Header

一般情况是用它来设置顶部大banner图片的。这个就看你怎么灵活应用了。

也是 3.4 版本引进的,让主图支持自定义头图。

header_image()与get_custom_header()

对应

我们可以在后台的 外观==>顶部 (如下图)

$args = array(
'flex-width' => true,//自适应高度
'width' => 250, //宽
'flex-width' => true,//自适应宽度
'height' => 250, //高
'default-image' => get_template_directory_uri() . '/img/logo.jpg', //默认logo图
);
add_theme_support( 'custom-header', $args );

使用

<img
src="<?php header_image(); ?>"  //获取自定义顶部图片的地址
height="<?php echo get_custom_header()->height; ?>" //获取图片高
width="<?php echo get_custom_header()->width; ?>" //获取图片宽

/>

这篇文章对您有用吗?

我们要如何帮助您?