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' );
}

Featured Plugin - WordPress Infinite SEO Plugin

Fully integrated with the SEOMoz API, complete with automatic links, sitemaps and SEO optimization of your WordPress setup - this is the only plugin you need to help you rank your site number 1 on Google - nothing else compares.
Find out more

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 );

Featured Plugin - WordPress Newsletter Plugin

Now there's no need to pay for a third party service to sign up, manage and send beautiful email newsletters to your subscriber base - this plugin has got the lot.
Find out more

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:

Featured Plugin - WordPress Appointments Plugin

Take, set and manage appointments and client bookings without having to leave WordPress. Appointments+ makes it easy.
Find out more

Comments (6)

  1. Dude, those filters are used for translating text, not changing it! Argh! You’re running an str_ireplace on every single string passed through the translation functions, which can be thousands! That’s so lame!

    • Hi Konstantin. Thanks for sharing your thoughts on this. I agree that these are translation filters and that the str_ireplace function is being used, but do you have a better way to achieve the same result? If so, I’d be happy to update the post. I’m not the world’s best coder, but I love making things better — more optimized code, better user experience, etc — which was the aim of this snippet. Please share any suggestions. Thank you very much.

      • If you’d like to edit the title of any of the meta boxes in the edit post screen, hook the do_meta_boxes action and play around with the $wp_meta_boxes global. Here’s a quick example of how to add stuff to the featured image metabox: https://gist.github.com/3376828 beware that the action can be run several times and in different contexts, so don’t forget to check post_type_supports, and remove your action when you’re done.

        If you’d like to “replace any text within wp-admin” just create your own translation file. Compiled .mo files are *way* faster than whatever you’re trying to do, and it’s perfectly legal to create custom translations to suit your needs, just as it is legal to create different translations for English, like “English (UK)” and “English (Canada)” and a bunch of others: http://translate.wordpress.org/projects/wp/3.4.x and all of this is also true for front-end, plugins, themes and everything else.

        Long story short: never hijack the translation functions.

        • Konstantin, I updated the post to rid it of all translation-hacking. Thank you VERY much for your high standards and skills. I hope you also like the version for when different post types have different featured image dimensions.

          Have a great weekend!

Participate