微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

wordpress使用add_theme_support实现自定义头部图像

add_theme_support是wordpress一个常用函数,让主题支持一些特定功能wordpress 函数:add_theme_support()让你的主题支持特定的功能

今天我们借助官网文档,具体看看如何实现wordpress主题头部图像自定义的。

从wp Version 3.4,主题开始使用 add_theme_support() 在 functions.PHP 文件中,可以自定义头部的一些背景颜色,图像等等,例如:

add_theme_support( 'custom-header' );

这样便会在WP后台-外观-出现-顶部菜单,从而进行头部图像自定义设置。

参数使用

$defaults = array(

'default-image' => '',

'width' => 0,

'height' => 0,

'flex-height' => false,

'flex-width' => false,

'uploads' => true,

'random-default' => false,

'header-text' => true,

'default-text-color' => '',

'wp-head-callback' => '',

'admin-head-callback' => '',

'admin-preview-callback' => '',

);

add_theme_support( 'custom-header',$defaults );

实例

1、设置一个自定义头形象

设定认头部图片 980px width, 60px height:

$args = array(

'width' => 980,

'height' => 60,

'default-image' => get_template_directory_uri() . '/images/header.jpg',$args );

Upload other custom header images

2、设置一个标题形象和允许网站所有者上传其他图片:

$args = array(

'width' => 980,

'uploads' => true,$args );

3、灵活头部设置

$args = array(

'flex-width' => true,

'width' => 980,

'flex-height' => true,

'height' => 200,$args );

头部文件 header.PHP调用

PHP header_image(); ?>" height="PHP echo get_custom_header()->height; ?>" width="PHP echo get_custom_header()->width; ?>" alt="" />

官方文档

https://codex.wordpress.org/Custom_Headers

原文地址:https://www.jb51.cc/wordpress/422820.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐