WordPress 3.0 TwentyTen Child Theme Header Image

The new Twenty Ten theme for WordPress 3.0 provides support for uploading custom header images. Uploaded images are cropped to 940 x 198 pixels. So your options are:

  1. Ensure that your header image size is 940 x 198 pixels.
  2. Modify the Twenty Ten theme to change this size
  3. Create a child theme which overrides the size

I’m going to show you how to do option 3: change the Twenty Ten theme header image size. “Creating a child theme is the way of the future” (I think that Yoda said that, but I’m not sure).

The Twenty Ten header image size is defined in the functions.php function twentyten_setup(). The WordPress team has thoughtfully provided filters to simplify overriding the default height and width:

// The height and width of your custom header.
// You can hook into the theme's own filters to
// change these.
// Add a filter to twentyten_header_image_width
// and twentyten_header_image_height to change these values.
define( 'HEADER_IMAGE_WIDTH',
   apply_filters( 'twentyten_header_image_width', 940 ) );
define( 'HEADER_IMAGE_HEIGHT',
   apply_filters( 'twentyten_header_image_height', 198 ) );

You can define filters named “twentyten_header_image_width” and “twentyten_header_image_height” which will override the default values of 940 and/or 198.

To create filters which override these values, create a functions.php file in your child theme and add the following lines:

add_filter('twentyten_header_image_height','my_header_height');
add_filter('twentyten_header_image_width','my_header_width');
function my_header_height($size){
   return 300;
}
function my_header_width($size){
   return 900;
}

In this case I am ignoring the default sizes that are passed into the filter and simply setting them to the values that I want (900×300).
Be sure to change the prefix ‘my_’ to something more appropriate and unique to your child theme to avoid possible naming conflicts.

That’s all it takes! Use the Appearance -> Header control panel to upload a new header image now. The control panel should now display the size that you set with these filters, and the new size reflected on the website.

Now having said that, I subsequently decided that I want different sizes and layouts for the front and other pages, so I ultimately modified the header.php file. Don’t judge me.

This entry was posted in Child Themes, Web Programming, WordPress and tagged , , , . Bookmark the permalink.

7 Responses to WordPress 3.0 TwentyTen Child Theme Header Image

  1. Matti says:

    Hi Ron, Could a filter be added to the functions page to display all the header images on one page? instead of just one?

  2. Ron Lisle says:

    Can you elaborate more? Do you mean showing all the images in the admin panel or something else?

  3. Matti says:

    I was hoping of using the all the images in the Twentyten header as a slideshow, but to do this I need to be able to load all the images into the page not just one, I wondered if there was a modification that could be made that would allow all the header images to load into the page.

  4. marvin says:

    the code works. thanks. its hard to type on your comment box

  5. Ron Lisle says:

    Marvin,
    It sure is. Like looking for a white rabbit in a snow storm! Thanks for pointing it out to me. I’ve fixed my template now.

  6. Thirzah says:

    *gives Ron a gold star* Thank you for perfect advice :)

  7. Thanks! This is exactly what I needed to do this morning and your write-up was perfect.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>