I’ve created a new custom post type and I need the post thumbnails or featured images generated by the get_the_post_thumbnail()
function to be set in percent, rather than pixels, as I’m using a fluid grid. Ideally I would only set the width (to 100%). Is there a way to do this? Potentially using add_image_size()
?
3 Answers
have you tried,
if(has_post_thumbnail()) {
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
echo '<img src="' . $image_src[0] . '" width="100%" />';
}