How do I set the medium and large images sizes in WP to hard crop?
In my theme I can set the thumbnail size to hard crop using this:
add_theme_support('post-thumbnails');
set_post_thumbnail_size( 96, 96, true );
But I can see no way to make the medium and large images to hard crop.
Is there possibly a way to remove the medium and large sizes and re-add them using:
add_image_size( 'medium', $width, $height, true );
add_image_size( 'large', $width, $height, true );
You can over write the default like this:
Here’s an improvement that uses the settings as you tried to do:
add_image_size('medium', get_option( 'medium_size_w' ), get_option( 'medium_size_h' ), true );
To enable cropping for the
medium
images, it is enough to use this code:The
update_option()
function itself checks whether such an option exists, and adds it if necessary:The Gleb’s answer worked nicely for me.
Found the full code here