Title: consistent thumbnail width?
Last modified: August 19, 2016

---

# consistent thumbnail width?

 *  [alfresco](https://wordpress.org/support/users/alfresco/)
 * (@alfresco)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/consistent-thumbnail-width/)
 * I’m attempting to set my default thumbnail size in such a way that my width will
   always be consistent – ideally 550px. An example can be found here: [http://www.look-closer.net](http://www.look-closer.net)
 * I have managed to set my long edge to whatever my heart desires, but am having
   trouble making a static base, and dynamic height while preserving whatever ratio
   my original file happens to have.
 * I found this on another board:
 * if ( $metadata[‘width’] >= $metadata[‘height’] ) {
    $max_side = apply_filters(‘
   wp_thumbnail_max_side_length’, 150, $attachment_id, $file ); } else { $max_side
   = apply_filters( ‘wp_thumbnail_max_side_length’, 200, $attachment_id, $file );}
 * to replace line 153 in my image.php file, the line that determines long edge 
   length. Unfortunately, this only works for images of a specific ratio, as far
   as I have been able to tell.
 * I am using Barthelme 1.1 for a theme, more or less, which came with my WP install.
   You can view my page in its infancy at alfresco.geminetix.com. I’ve just started
   playing with wordpress, so all the images are random pictures I’ve taken, with
   pretty random comments, just to get an idea of layout.
 * I appreciate any help- and hurrah for a first time post!

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [forresto](https://wordpress.org/support/users/forresto/)
 * (@forresto)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/consistent-thumbnail-width/#post-666771)
 * Make thumbsize.php in your plugins directory and enable this plugin:
 *     ```
       <?php
   
       /*
       Plugin Name: Thumbnail Sizes
       Plugin URI: http://wordpress.org/support/topic/147572
       Description: Fixed thumbnail width.
       Version: 1.0
       Author: Forrest O.
       Author URI: http://sembiki.com/
       */
   
       // 	change thumbnail to consistent width
       function custom_thumbsize( $size, $attachment_id, $file )
       {
       	$th_width = 550;
   
       	$image_attr = getimagesize( $file );
   
       	if ( $image_attr[0] < $image_attr[1] )
       	{
       		// 	image is portrait, make it fit in the width
       		return round( $image_attr[1] / $image_attr[0] * $th_width );
       	}
       	else
       	{
       		// 	image square or landscape, make it fit the width
       		return $th_width;
       	}
       }
   
       add_filter( 'wp_thumbnail_max_side_length', 'custom_thumbsize', 10, 3 );
   
       ?>
       ```
   
 * Does this work for you? Doing it as a plugin gives you the advantage of not overwriting
   changes on an upgrade.
 *  [forresto](https://wordpress.org/support/users/forresto/)
 * (@forresto)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/consistent-thumbnail-width/#post-666772)
 * alternately, just add this to functions.php for your theme:
 *     ```
       // 	change thumbnail to consistent width
       function custom_thumbsize( $size, $attachment_id, $file )
       {
       	$th_width = 550;
   
       	$image_attr = getimagesize( $file );
   
       	if ( $image_attr[0] < $image_attr[1] )
       	{
       		// 	image is portrait, make it fit in the width
       		return round( $image_attr[1] / $image_attr[0] * $th_width );
       	}
       	else
       	{
       		// 	image square or landscape, make it fit the width
       		return $th_width;
       	}
       }
   
       add_filter( 'wp_thumbnail_max_side_length', 'custom_thumbsize', 10, 3 );
       ```
   
 *  [forresto](https://wordpress.org/support/users/forresto/)
 * (@forresto)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/consistent-thumbnail-width/#post-666773)
 * On testing, the plugin version works for me, but the functions.php version doesn’t
   seem to…
 *  [cosmocanuck](https://wordpress.org/support/users/cosmocanuck/)
 * (@cosmocanuck)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/consistent-thumbnail-width/#post-666785)
 * Hi! How would I modify this code/plugin to only affect images with the “medium”
   size, not “thumbnail”? I’d like them all to be 250px wide, whether landscape,
   square or vertical.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘consistent thumbnail width?’ is closed to new replies.

## Tags

 * [constant](https://wordpress.org/support/topic-tag/constant/)
 * [thumbnail](https://wordpress.org/support/topic-tag/thumbnail/)
 * [width](https://wordpress.org/support/topic-tag/width/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [cosmocanuck](https://wordpress.org/support/users/cosmocanuck/)
 * Last activity: [17 years, 10 months ago](https://wordpress.org/support/topic/consistent-thumbnail-width/#post-666785)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
