CHAPTER 6 • Advanced Theme Usage 147
That’s all there is to it. Now the user can add a menu to the Smashing Menu area in the theme
as well, using the wp_nav_menu() template tag, like so:
<?php wp_nav_menu( array( 'theme_location' => 'smashing-menu' ) ); ?>
This will let you populate this particular menu from the menu interface found under
Appearance ➪ Menu in the admin interface. That’s it. Simple, huh?
CUSTOM HEADERS
Adding support for a custom header isn’t particularly complicated, but it does require a few
lines of code in functions.php. As of WordPress version 3.4 and later, this has changed, so if
you intend to make your theme backward compatible with versions prior to 3.4, you need to
do some checks and alter your code. Obviously, this is not recommended (you should run the
latest version of WordPress), so let’s focus on the current way to do this and forget about the
past for now. It is noted here just in case you run into different code or have an issue with an
old version of WordPress.
Just as with most other custom features you add to your theme, you use addtheme
support() to enable custom headers:
// Add custom header support
add_theme_support( 'custom-header' );
This will enable custom headers, but to really take control of the feature, you’ll want to pass
some parameters too. These are the default values:
$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' => '',
);
add_theme_support( 'custom-header', $defaults );
These parameters are described in the Codex (http://codex.wordpress.org/Custom_
Headers), and the actual settings that you need for your custom headers depend entirely on
your theme. However, there are a few things that you’ll no doubt want to set, such as the
dimensions. The width and height parameters take pixel values, so you can easily set