I am debugging my theme using Debug Bar plugin, which is showing me this error (among a few others):
Notice: add_custom_image_header
is deprecated since version 3.4! Use add_theme_support( 'custom-header', $args )
instead.
Okay, clearly, it says I need to use this instead of this. The question is, add_custom_image_header
has three parameters, namely:
- $header_callback
- $admin_header_callback
- $admin_image_div_callback
How do I represent them in add_theme_support
function? Like this?
$aahan_custom_header_args = array(
'wp-head-callback' => '',
'admin-head-callback' => '',
'admin-preview-callback' => '',
);
add_theme_support( 'custom-header', $aahan_custom_header_args );
Also, are wp-head-callback
, admin-head-callback
, and admin-preview-callback
, the exact replacements for $header_callback
, $admin_header_callback
, and $admin_image_div_callback
respectively?
Please read Updating Custom Backgrounds and Custom Headers for WordPress 3.4.
Custom Headers
Old method:
// Define default header image constant
define( 'HEADER_IMAGE', get_template_directory_uri() . '/images/headers/default.jpg' );
// Define header image width constant
define( 'HEADER_IMAGE_WIDTH', 1000 );
// Define header image height constant
define( 'HEADER_IMAGE_HEIGHT', 198 );
// Define header text constant
define( 'NO_HEADER_TEXT', false );
// Define header text color constant
define( 'HEADER_TEXTCOLOR', '000' );
// Turn on random header image rotation by default.
// Requires HEADER_IMAGE to be null
add_theme_support( 'custom-header', array( 'random-default' => true ) );
// Add Theme support
add_custom_image_header( $wphead_cb, $adminhead_cb, $adminpreview_cb );
New method:
add_theme_support( 'custom-header', array(
// Header image default
'default-image' => get_template_directory_uri() . '/images/headers/default.jpg',
// Header text display default
'header-text' => false,
// Header text color default
'default-text-color' => '000',
// Header image width (in pixels)
'width' => 1000,
// Header image height (in pixels)
'height' => 198,
// Header image random rotation default
'random-default' => false,
// Template header style callback
'wp-head-callback' => $wphead_cb,
// Admin header style callback
'admin-head-callback' => $adminhead_cb,
// Admin preview style callback
'admin-preview-callback' => $adminpreview_cb
) );
Again: that was easy, wasn’t it?
Just to clarify, here are the old-constant/new-array-key equivalents:
HEADER_IMAGE => 'default-image'
HEADER_IMAGE_WIDTH => 'width'
HEADER_IMAGE_HEIGHT => 'height'
NO_HEADER_TEXT => 'header-text'
HEADER_TEXTCOLOR => 'default-text-color'
All of the same callbacks are supported, exactly as before.
For reference, here is the complete defaults array:
$defaults = array(
'default-image' => '',
'random-default' => false,
'width' => 0,
'height' => 0,
'flex-height' => false,
'flex-width' => false,
'default-text-color' => '',
'header-text' => true,
'uploads' => true,
'wp-head-callback' => '',
'admin-head-callback' => '',
'admin-preview-callback' => '',
);