Add WordPress’ Custom Header Options Page to Your Own Theme

WordPress 3.4 includes some great functions for giving your users more options for customizing their themes. One of my favorites is the Custom Header Image screen.

If you’re using WordPress’ stock Twenty Twelve theme, you can find it under the Appearance -> Header menu. Here’s what it looks like:

But did you know you can add this screen to your own themes?

Its actually quite easy. You’ll just need to add this code to functions.php:

	// Note: this code will only work in WordPress 3.4 or newer.
	$defaults = array(
		'default-image'		  => get_template_directory_uri() . '/images/header.jpg',
		'width'				  => 960,
		'height'				 => 300,
	add_theme_support( 'custom-header', $defaults );

Then when you want to output this header image in your theme’s source code, just use the new get_custom_header function:

For more information on the get_custom_header function, refer to the WordPress Codex.

Facebook Comments