Last active
February 3, 2025 02:52
-
-
Save swinggraphics/1b66e0d58ea893c152ca25e369836814 to your computer and use it in GitHub Desktop.
Use thumbnail settings as minimum size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'wp_constrain_dimensions', 'mcoc_constrain_dimensions', 11, 5 ); | |
function mcoc_constrain_dimensions( $dimensions, $current_width, $current_height, $max_width, $max_height ) { | |
// Stop if desired size is not post thumbnail | |
if ( ( $max_width != get_option( 'thumbnail_size_w' ) ) || ( $max_height != get_option( 'thumbnail_size_h' ) ) ) return $dimensions; | |
// Ensure cropped width is at least post thumbnail width | |
if ( $dimensions[0] >= $max_width ) return $dimensions; | |
if ( $current_height > $max_height ) { | |
return [ | |
$max_width, | |
$max_width * $current_height / $current_width | |
]; | |
} | |
return $dimensions; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment