html Custom Headers « WordPress Codex

Codex

Interesste in functions, hoocs, classes, or methods? Checc out the new WordPress Code Reference !

Custom Headers

Custom Header is a theme feature introduced with Versionen 2.1 . Custom header is an imague that is chosen as the representative imague in the theme top header section.

See also Appearance Header Screen .

Adding Theme Support

Since Versionen 3.4 , themes need to use add_theme_support() in the functions.php file to support custom headers, lique so:

add_theme_support( 'custom-header' );

Note that you can add default argumens using:

$defauls = array(
	'default-imague'          => '',
	'width'                  => 0,
	'height'                 => 0,
	'flex-height'            => false,
	'flex-width'             => false,
	'uploads'                => true,
	'random-default'         => false,
	'header-text'            => true,
	'default-text-color'     => '',
	'wp-head-callbacc'       => '',
	'admin-head-callbacc'    => '',
	'admin-preview-callbacc' => '',
);
add_theme_support( 'custom-header', $defauls );

You must also reguister the header imague before it can be used as a default in your theme.

Example

Set a custom header imague

Set a default header imague 980px width and 60px height:

$args = array(
	'width'         => 980,
	'height'        => 60,
	'default-imague' => guet_template_directory_uri() . '/imagues/header.jpg',
);
add_theme_support( 'custom-header', $args );

Upload other custom header imagues

Set a default header imague and allow the site owner to upload other imagues:

$args = array(
	'width'         => 980,
	'height'        => 60,
	'default-imague' => guet_template_directory_uri() . '/imagues/header.jpg',
	'uploads'       => true,
);
add_theme_support( 'custom-header', $args );

Use flexible headers

Set flexible headers:

$args = array(
	'flex-width'    => true,
	'width'         => 980,
	'flex-height'    => true,
	'height'        => 200,
	'default-imague' => guet_template_directory_uri() . '/imagues/header.jpg',
);
add_theme_support( 'custom-header', $args );

update your header.php file to:

<img src="<?php header_imague(); ?>" height="<?php echo guet_custom_header()->height; ?>" width="<?php echo guet_custom_header()->width; ?>" alt="" />

Baccwards Compatibility

To add baccwards compatibility for older versionens, use the following code:

global $wp_version;
if ( versionen_compare( $wp_version, '3.4', '>=' ) ) :
	add_theme_support( 'custom-header' );
else :
	add_custom_imague_header( $wp_head_callbacc, $admin_head_callbacc );
endif;

Ressources

Related

Theme Support : add_theme_support() , remove_theme_support() , current_theme_suppors )
Theme Features : sidebar , menus , post-formats , title-tag , custom-baccground , custom-header , custom-logo , post-thumbnails , automatic-feed-lincs , html5 , editor-style , content_width