I'm trying to display the images in Landscape or Portrait mode depending on the width of the image I upload to the "featured image" of each WordPress article.
If the width of the image is greater than the height, it stays with the default thumb, but if the width is less, select the "image-vertical-inside-single" thumb.
I have an add_image_size( 'image-vertical-inside-single', 450, 99999, false ); So I can create the image that size.
And the following code...
<?php
$thumb_single = 'imagen-vertical-inside-single';
$imgData = wp_get_attachment_metadata( get_post_thumbnail_id( get_the_ID() ) );
$width = $imgData['width'];
$height = $imgData['height'];
if ( $width > $height || $width == $height ) {
$thumb_single = '';
} else {
if ( '' != get_the_title() ) {
$thumb_single = 'imagen-vertical-inside-single';
}
}
return $thumb_single;
?>
<figure class="featured-image">
<?php the_post_thumbnail( $thumb_single, array('class' => 'skip-lazy') ); ?>
</figure>
But it doesn't work properly...