Setting width only on post featured image

WordPress allows you to set a featured image for a post or a page. You can call this featured image (thumbnail) in the loop, but you are restricted to how the thumbnail is sized. The options range from the default thumbnail size (150×150), but this cuts off part of the image. The rest of the options are the standard sizes: medium, large, and original size. The other option is to set your height and width using an array.

Recently I was tasked with posting either the thumbnail or the excerpt from a post, but the space where the loop was placed is limited in width. Since you cannot declare just a height *or* just a width, I had to find a work-around to avoid distorting the thumbnail.

#blog article img {
width: 170px;
height: auto;

Usually I would set just the width on the actual image itself, but since I don’t have access to the raw HTML, I had to simply use the CSS to define my dimensions. Set the width to what I want and set the height to ‘auto.’ This will resize the height automatically to retain the dimensions of the image while still resizing it to the desired width. Easy enough.

Leave a Reply

Your email address will not be published. Required fields are marked *