WordPress Templates

WordPress: custom-header & custom-background

A WordPress function called add_theme_support allows you to add a range of features to your themes.

The link to the codex section discussing add_theme_support() is http://codex.wordpress.org/Function_Reference/add_theme_support

The syntax is as follows:

<?php add_theme_support ( feature );  ?>

For example, to add custom backgrounds to your themes, you would add to your functions.php file the following code:

<?php add_theme_support ( 'custom-background'  ); ?>

To add a custom header functionality, you would add the following:

<?php add_theme_support ( 'custom-header'  ); ?>

Some uses of this function can accept additional parameters. For example, the above custom-header call can be enhanced as follows:

$headerAttributes = array(
'flex-width' => true,
'width' => 960,
'flex-height' => true,
'height' => 200,
'default-image' => get_template_directory_uri() . '/images/header.jpg'
);

 add_theme_support ( 'custom-header', $headerAttributes );

Once you’d added this to your functions.php file, the only other thing you would have to do is explicitly call the custom header in a template file (most likely header.php), like so:

<img src="<? php header_image();  ?>" >

Standard