Currently, I am working on developing a custom WordPress theme and here is the code snippet that I have been using:
<div class="post-thumb">
<?php echo get_the_post_thumbnail(); ?>
</div>
I am facing an issue where I need to adjust the width and height of post thumbnails based on their dimensions. If the height is greater than the width, then set width=100% and height=auto. On the other hand, if the width is greater than the height, then set the height=100% and width=auto.
I attempted to achieve this functionality with JavaScript but unfortunately, it did not work as expected!
var landscape = $(".post-thumb img ").css('width');
var portrait = $(".post-thumb img ").css('height');
if (landscape > portrait){
$(".post-thumb img").height('100%') .width('auto');}
else {
$(".post-thumb img").width('100%') .height('auto');}
If you have any solution or suggestion on how I can resolve this issue, please feel free to share!