clubmate.fi

A good[ish] website

Web development blog, loads of UI and JavaScript topics

Add image sizes to WordPress

Filed under: WordPress/PHP— Tagged with: functions.php, snippets

Heres how to add more image sizes to WordPress.

This goes in your theme’s functions.php file:

if ( function_exists( 'add_image_size' ) ) {
  // Non cropped tall thumb with 3:4 ratio
  add_image_size( 'tall_thumbnail', 80, 107 );

  // Small 30x30 cropped thumb
  add_image_size( 'tiny_thumbnail', 30, 30, true );
}

Here’s what the parameters do:

$name
Image size identifier.
$width
Image width in pixels. Default 0.
$height
Image height in pixels. Default 0.
$crop
Image cropping behavior. If false, the image will be scaled (default), If true, image will be cropped to the specified dimensions using center positions. If an array, the image will be cropped using the array to specify the crop location. Array values must be in the format: array( x_crop_position, y_crop_position ) where:
  • x_crop_position accepts: 'left', 'center', or 'right'.
  • y_crop_position accepts: 'top', 'center', or 'bottom'.
Default value: false

Comments would go here, but the commenting system isn’t ready yet, sorry.

  • © 2022 Antti Hiljá
  • About
  • All rights reserved yadda yadda.
  • I can put just about anything here, no one reads the footer anyways.
  • I love u!