Custom thumbnail sizes in WordPress: tips and hints to master them

I am working on a new WordPress theme and have identified several issues with the thumbnails.

Some initial clarifications:

When you use the function to get the thumbnail from a post, what you will be getting is the featured image.

Initially WordPress comes with pre-defined sizes by default:

the_post_thumbnail('thumbnail');       // Thumbnail (default 150px x 150px max)
the_post_thumbnail('medium');          // Medium resolution (default 300px x 300px max)
the_post_thumbnail('large');           // Large resolution (default 640px x 640px max)
the_post_thumbnail('full');            // Original image resolution (unmodified)

 source: http://codex.wordpress.org/Post_Thumbnails

You can define custom sizes and names for new types of thumbnails. 

But you will have to regenerate the thumbnails in order to have the new images created, in case you would like to use the “crop” parameter, that is, that the image created will not be a resize, but rather taking the content from the center of the existing full-size image. 

This is explained pretty well here: http://codex.wordpress.org/Function_Reference/add_image_size

What is not explained in the Codex documentation is that the crop option will not work unless you regenerate the thumbnails. How do you regenerate the thumbnails?

There are several alternatives that I am aware of:

1. Delete permanently and upload the image again

2. Use the regenerate thumbnail plugin: http://wordpress.org/plugins/regenerate-thumbnails/

3. With PHP code, doing something like this:

include( ABSPATH . ‘wp-admin/includes/image.php’ );
wp_generate_attachment_metadata( $thumbnail_id, $absolute_path_to_image );

following this: 

http://codex.wordpress.org/Function_Reference/wp_generate_attachment_metadata

A discussion on this can also be found here http://wordpress.stackexchange.com/questions/35833/the-post-thumbnail-hard-cropping-not-working-no-matter-what/128032#128032

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s