Never forget your Featured Image Dimensions

Updated August 31, 2012: Thanks to one of the commenters and one of our own developers, the first 2 code snippets have been completely replaced with much-improved, completely different code compared to this post’s original content. As this is one of my favorite bits of functionality, I am very grateful.

All Featured Images Have the Same Dimensions

The following code provides you and your authors with a constant reminder of your ideal Featured Image size so your Featured Images always look their best.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
add_action( 'do_meta_boxes', 'my_do_meta_boxes' );
function my_do_meta_boxes( $post_type ) {
global $wp_meta_boxes;
if ( ! current_theme_supports( 'post-thumbnails', $post_type ) || ! post_type_supports( $post_type, 'thumbnail' ) )
return;

foreach ( $wp_meta_boxes[ $post_type ] as $context => $priorities )
foreach ( $priorities as $priority => $meta_boxes )
foreach ( $meta_boxes as $id => $box )
if ( 'postimagediv' == $id )
$wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $id ]['title'] .= ' 440w x 300h';

remove_action( 'do_meta_boxes', 'my_do_meta_boxes' );
}

Different Featured Image Sizes for each Post Type

If your Posts have a Featured Image size of 440 x 300, your Pages have a Featured Image size of 600 x 200, and your Testimonials custom post type has a Featured Image size of 250 x 250, you need this code instead of the code above.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function image_size_html($content =''){
global $post_ID;

$post_type = get_post_type($post_ID);

if ( ! ( post_type_supports( $post_type, 'thumbnail' )
&& current_theme_supports( 'post-thumbnails', $post_type ) ) )
return $content;

switch($post_type) {
case 'post' : $dim = ' (440w × 300h)'; break;
case 'page' : $dim = ' (600w × 200h)'; break;
case 'testimonials' : $dim = ' (250w × 250h)'; break;
default : $dim ='';

}

$content = str_replace(esc_attr__( 'Set featured image' ), esc_attr__( 'Set featured image' ) . $dim, $content);
return $content;
}

add_filter( 'admin_post_thumbnail_html', 'image_size_html', 9999, 1 );

Combine with other Featured Image tools

Because Featured Images are displayed according to the theme’s specifications, these snippets are probably best kept within your theme’s functions.php file instead of in a separate plugin.

I hope you enjoyed these snippets. You might want to use them in combination with these helpful articles: