December 18, 2019
Style images differently according to weather the image is landscape, portrait, or even square.
<?php if ( has_post_thumbnail()) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'large' );
$image_w = $image[1];
$image_h = $image[2]; ?>
<div class="<?php echo $base_class; ?>__post-thumbnail
<?php if ($image_w > $image_h) {
echo 'landscape';
} elseif ($image_w == $image_h) {
echo 'square';
} else {
echo 'portrait';
} ?>">
<?php the_post_thumbnail(); ?></a>
</div>
<?php } ?>
The above will add a class for each orientation that can be targeted using CSS.