Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I know I can set up post, pages, and custom post types to use featured images in wordpress by enabling theme support:

add_theme_support( 'post-thumbnails');

Or enabling theme support for a specific set of post types:

    add_theme_support( 'post-thumbnails', array('post','page'));

I also know that I can add an "image size" like this:

add_image_size( 'media_library', 333, 230, true );

But how do you control which image size of the "feature image" actually displays on the edit screen of Wordpress? For example in TwentyEleven I have uploaded a square photo and it shows up as a rectangle in the featured image box on the edit screen:

Picture 1.png

How do you pick which image size shows up there?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

I believe that is what the set_post_thumbnail_size function is for.

Set the default Post Thumbnail dimensions. To register additional image sizes for Post Thumbnails use: add_image_size().

See http://codex.wordpress.org/Function_Reference/set_post_thumbnail_size

share|improve this answer

If you added a custom with the 3 sizes:

add_image_size( 'small', 111, 222, true );
add_image_size( 'medium', 333, 333, true );
add_image_size( 'large', 444, 555, true );

You would then use them in the theme files using the names you gave for the function like this:

<?php the_post_thumbnail('small'); ?>

or

<?php the_post_thumbnail('medium'); ?>

and:

<?php the_post_thumbnail('large'); ?>

Existing images would need to be regenerated by using the regenerate post thumbnails plugins, but all new ones would get cropped as specified.

share|improve this answer
    
That's helpful, but per the question "How do you control which image size of the "feature image" actually displays on the edit screen of Wordpress?" –  cwd Jan 17 '12 at 4:26
    
Hmm, I guess I misunderstood you. To get them smaller would be simple by just adding some extra style to the editor-style.css file (if your theme uses one). You're pretty limited in that area since it needs to be contained to the right side of the post screen. I've noticed for best results as far as the UI goes is to use proportional images vs. the actual size of the thumbnail itself. A 300X900px image that get's cropped to 250X400px might look somewhat awkward. What is your reasoning for controlling the post editor size of things? Maybe that will clean r up for better instructions. –  Jeremy Jared Jan 17 '12 at 5:48

Doing a search for Featured Image I was lead to \wp-admin\edit-form-advanced.php, where I found a metabox being added with a callback param of post_thumbnail_meta_box.

I then did a search for post_thumbnail_meta_box, and ended up in \wp-admin\includes\meta-boxes.php, where we can see that WP gets the post thumbnail with:

$thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );

and then does some magic on it with this:

echo _wp_post_thumbnail_html( $thumbnail_id );

Searching for function _wp_post_thumbnail_html leads us to \wp-admin\includes\post.php, where we see that WP determines the size it wants to use, but then at the very last instant, we are given the opportunity to mess with the image via:

return apply_filters( 'admin_post_thumbnail_html', $content );

Example:

function admin_post_thumbnail_kittenifier( $content ) {
    // In reality, you might want to replicate some of the code from _wp_post_thumbnail_html(), but this gives you the idea
    return "<img src='http://placekitten.com/200/300' alt='I can has toxoplasma gondii?'/>";
}
add_filter( 'admin_post_thumbnail_html', 'admin_post_thumbnail_kittenifier' );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.