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?

Read More

If yes, how to implement to the functions.php

Related posts

Leave a Reply

3 comments

  1. 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 );
    
    }
    
  2. 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.