• Hi all,

    Bit of a weird request, this one. I would like to change the suffix that WordPress inserts when creating thumbnail and medium image sizes. I had a look at media.php in the wp-includes folder and found that this variable ($suffix) is declared on line 360:

    $suffix = “{$dst_w}x{$dst_h}”;

    Instead of having the new image widths and heights inserted into the name ($dst_w and $dst_y) I would just like to have “thumb” and “medium” i.e. when uploading “image.jpg” wordpress creates “image-thumb.jpg” and “image-medium.jpg”.

    Hope that makes sense.

    Any help, as ever, would be greatly appreciated.

    Cheers.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Not weird at all… I’d really love to hear the solution for this one as well. I suspect it can be done by using filter + action hooks, but the code I’m working on is really not doing it properly… this is what I’m working on so far in my functions.php:

    function change_image_suffix($suffix) {
    	if ($size == 'thumb' || $size == 'thumbnail') {
    	$suffix = '.thumb';
    	} elseif ($size == 'medium') {
    	$suffix = '.medium';
    	} elseif ($size == 'large') {
    	$suffix = '.large';
    	} else {
    	$suffix = '';
    	}
    	return $suffix;
    }
    add_filter('image_resize','change_image_suffix');

    I’m really sure there must be something fundamental missing here… I’m not a great coder, and all I can do is google-research the hell out of my code… and if it’s not in the google-sphere, then I will also never know, unfortunately.

    This naming convention would make things SO MUCH EASIER when automating the display of images according to size-standards rather than size… any help would be very very appreciated!!!

    Fei

    Playing off what fltseng wrote I came up with this:

    /wp-includes/media.php line #363:

    if ( !$suffix )
    {
      switch ($max_w) {
        case (intval(get_option('large_size_w'))):
          $suffix = 'large';
          break;
        case (intval(get_option('medium_size_w'))):
          $suffix = 'medium';
          break;
        case (intval(get_option('thumbnail_size_w'))):
          $suffix = 'thumbnail';
          break;
        default:
          $suffix = 'other';
      }
    }

    It’s a hack, unfortunately, instead of a plugin, but it works for me so far.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘$suffix in Media.php’ is closed to new replies.