iamafish
iamafish

Reputation: 817

Crop thumbnail to exact dimensions on Wordpress for medium size

In Wordpress Media Settings the Thumbnail size we can crop thumbnail to exact dimensions.

But for the Medium size no option to get exact dimensions. There have a way to force exact dimensions for medium size?

If yes, how to implement to the functions.php

Upvotes: 2

Views: 9927

Answers (3)

its_me
its_me

Reputation: 11338

As of now, there's a better way to do it. You can overwrite the default image sizes—namely thumbnail, medium and large—using the add_image_size function.

Examples:

// Set "Thumbnail" image size
if( function_exists( 'add_theme_support' ) ) {

    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 150, 150, false );

}

// Set "Medium" and "Large" image sizes
if( function_exists( 'add_image_size' ) ) {

    add_image_size( 'medium', 300, 9999, false );
    add_image_size( 'large', 1024, 9999, false );

}

Upvotes: 4

John P Bloch
John P Bloch

Reputation: 4581

Add this to your functions.php:

add_action( 'init', create_function( '', 'add_image_size( "cropped_medium", 300, 150, true );' ) );

The arguments are size name, width, height, and whether to force a crop.

Upvotes: -2

Jan Fabry
Jan Fabry

Reputation: 7351

If you want medium images to be cropped instead of scaled, like you can choose for the thumbnail size in the options page (but not for medium or large sizes), you can set the medium_crop option to true in your functions.php:

if(false === get_option("medium_crop")) {
    add_option("medium_crop", "1");
} else {
    update_option("medium_crop", "1");
}

Upvotes: 15

Related Questions