Custom Image Sizes

Custom Image Sizes is a WordPress plugin that

  • generates the correctly-sized version of an image’s thumbnail, if it doesn’t already exist.
  • lets you specify custom sizes with a size parameter of '[width]x[height]'.

By default, WordPress doesn’t create thumbnails on the fly

In default WordPress, when you call one of the WordPress image functions such as wp_get_attachment_image_src(), wp_get_attachment_image(), or image_downsize(), if the requested size doesn’t exist, WordPress will just scale down the fullsize version of the original image. This doesn’t always look great, and it’s a waste of bandwidth.

When Custom Image Sizes is active, it will instead create the requested thumbnail size.


The typical WordPress way

  • Put add_image_size( 'my_custom_thumbnail_name', 220, 130, true ); in your theme’s functions.php file.
  • Add the code to display that attachment’s thumbnail where you want it to appear: echo wp_get_attachment_image($attachment_id, 'my_custom_thumbnail_name');
  • Unlike WordPress by itself, Custom Image Sizes will generate the thumbnail for an image, even if the image was uploaded before this add_image_size() was set.

A more direct Custom Image Sizes way

  • Call wp_get_attachment_image_src() or wp_get_attachment_image() with the desired thumbnail '[width]x[height]' dimensions, like so:
    echo wp_get_attachment_image($attachment_id, '220x80');
     * The above prints markup like
     * <img width="220" height="80" title="" alt="" 
     *    class="attachment-220x80" src="" />


Support or Questions?

Please visit my support forum or (send me an email) austin (located at) pressedcode (dot) com.

Additional Resources