Generate Thumb in WP

In Wordpress its very easy to generate any size thumb of uploaded image using wp add_theme_support function.



WP add_theme_support() function create a thumb copy of the uploaded image with the specified dimensions when a new image is uploaded from the media gallery.

<?php add_image_size( $thumb-type-name, $width, $height, $crop); ?>


Note: To enable featured images with add_image_size function  in current theme it must include add_theme_support( 'post-thumbnails' ); in itsfunctions.php file. 

Parameters :
$thumb-type-name (string) (required)
- The new image size name.
Default: None

$width (int) (optional)
- The post thumbnail width in pixels.
Default: 0

$height (int) (optional)
- The post thumbnail height in pixels.
Default: 0

$crop (boolean/array) (optional) see Hard crop vs Soft crop
- crop images to specified height and width or resize based on soft and hard crop
  • false - Soft proportional crop mode.
  • true - Hard crop mode.
  • array - Specify positioning of the crop area (x_crop_position, y_crop_position).

Post a Comment

0 Comments