函数文档

add_custom_image_header()

💡 云策文档标注

概述

add_custom_image_header() 是一个已弃用的 WordPress 函数,用于为自定义图像头部显示添加回调函数。自 3.4.0 版本起,推荐使用 add_theme_support('custom-header', $args) 替代。

关键要点

  • 该函数已弃用,自 WordPress 3.4.0 起应改用 add_theme_support('custom-header', $args)。
  • 接受三个参数:$wp_head_callback(必需,在 'wp_head' 动作中调用)、$admin_head_callback(必需,在自定义头部管理屏幕调用)、$admin_preview_callback(可选,在管理预览屏幕输出图像 div)。
  • 内部将参数转换为数组并传递给 add_theme_support() 以注册自定义头部支持。

代码示例

function add_custom_image_header( $wp_head_callback, $admin_head_callback, $admin_preview_callback = '' ) {
    _deprecated_function( __FUNCTION__, '3.4.0', 'add_theme_support( 'custom-header', $args )' );
    $args = array(
        'wp-head-callback'    => $wp_head_callback,
        'admin-head-callback' => $admin_head_callback,
    );
    if ( $admin_preview_callback )
        $args['admin-preview-callback'] = $admin_preview_callback;
    return add_theme_support( 'custom-header', $args );
}

注意事项

  • 使用此函数会触发 _deprecated_function() 警告,建议更新代码以避免兼容性问题。
  • 相关函数包括 add_theme_support() 和 _deprecated_function(),用于主题支持和弃用标记。

📄 原文内容

Add callbacks for image header display.

Description

See also

Parameters

$wp_head_callbackcallablerequired
Call on the ‘wp_head’ action.
$admin_head_callbackcallablerequired
Call on custom header administration screen.
$admin_preview_callbackcallablerequired
Output a custom header image div on the custom header administration screen. Optional.

Source

function add_custom_image_header( $wp_head_callback, $admin_head_callback, $admin_preview_callback = '' ) {
	_deprecated_function( __FUNCTION__, '3.4.0', 'add_theme_support( 'custom-header', $args )' );
	$args = array(
		'wp-head-callback'    => $wp_head_callback,
		'admin-head-callback' => $admin_head_callback,
	);
	if ( $admin_preview_callback )
		$args['admin-preview-callback'] = $admin_preview_callback;
	return add_theme_support( 'custom-header', $args );
}

Changelog

Version Description
3.4.0 Deprecated. Use add_theme_support()
2.1.0 Introduced.