WordPress函数文档add_custom_image_header()
自定义头部图片 描述 译文 为图片页面显示添加回调。 回调参数$header_callback需要为’wp_h…
自定义头部图片
描述
译文
为图片页面显示添加回调。
回调参数$header_callback需要为’wp_head’动作显示内容。将回调参数 $admin_header_callback添加到Custom_Image_Header类中,将添加后的结果加入’admin_menu’动作
原文
Add callbacks for image header display.
The parameter $header_callback callback will be required to display the content for the ‘wp_head‘ action. The parameter $admin_header_callback callback will be added to Custom_Image_Header class and that will be added to the ‘admin_menu‘ action.
用法
<?php add_custom_image_header( $header_callback, $admin_header_callback, $admin_image_div_callback ) ?>
参数
$header_callback
(callback) (必填) Call on ‘wp_head‘ action.
默认值: None
$admin_header_callback
(callback) (必填) Call on custom header administration screen.
默认值: None
$admin_image_div_callback
(callback) (必填) Output a custom header image div on the custom header administration screen. Optional.
默认值: None
返回值
(void)
This function does not return a value.
示例
Edit the file functions.php inside your theme and add the following code.
Four constants must be defined in order for the custom image header to work:
1
2
3
4
5
6
7
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
define(‘HEADER_TEXTCOLOR’, ‘ffffff’);
define(‘HEADER_IMAGE’, ‘%s/images/default_header.jpg’); // %s is the template dir uri
define(‘HEADER_IMAGE_WIDTH’, 775); // use width and height appropriate for your theme
define(‘HEADER_IMAGE_HEIGHT’, 200);
|
If you don’t want to allow changing the header text color, add:
1
2
3
4
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
define(‘NO_HEADER_TEXT’, true );
|
Then change the first definition to:
1
2
3
4
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
define(‘HEADER_TEXTCOLOR’, ”);
|
If you intend to create child themes use:
1
2
3
4
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
define(‘HEADER_IMAGE’, trailingslashit( get_stylesheet_directory_uri() ).‘images/banner.jpg’);
|
Otherwise, you’ll pick up the header image for the parent theme rather than the child.
Next you need to write two functions. One will be included in the site header. The second will be included in the admin header. Both of these functions are required. The smallest possible amount of code would be something like this, although you can do anything you need.
1
2
3
4
5
6
7
8
9
10
11
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
// gets included in the site header
function header_style() {
?><style type=”text/css”>
#header {
background: url(<?php header_image(); ?>);
}
</style><?php
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
// gets included in the admin header
function admin_header_style() {
?><style type=”text/css”>
#headimg {
width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
background: no-repeat;
}
</style><?php
}
|
Finish with calling the add_custom_image_header function with the two earlier function names as parameters:
1
2
3
4
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
add_custom_image_header(‘header_style’, ‘admin_header_style’);
|
Taking this last step will make the Custom Header item appear in the Appearance menu. WordPress takes care of everything else.
注意
- 使用到: Custom_Image_Header. Sets up for $admin_header_callback for administration panel display.
历史
- Deprecated: 3.4.0
- 添加于 版本: 2.1.0
源文件
add_custom_image_header() 函数的代码位于 wp-includes/theme.php
.
相关
Custom Headers:
add_custom_image_header(),
remove_custom_image_header(),
register_default_headers(),
unregister_default_headers()
- 原文:http://codex.wordpress.org/Function_Reference/add_custom_image_header
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!