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调用官方文档https://codex.wordpress.org/Custom_Headers (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |