How do I add attributes in the img with the_post_thumbnail's WordPress function?

4

I need to add width="100%" and class="img-responsive" .

How do I add to the img if I call it in the index this way?

<?php the_post_thumbnail(); ?>
    
asked by anonymous 10.09.2015 / 07:30

1 answer

4

Do this:

<?php
  $thumb_id = get_post_thumbnail_id();
  $thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
  echo "<img src='".$thumb_url[0]."' width='100%' class='img-responsive' />";
?>

get_post_thumbnail_id takes the id of the thumb.

wp_get_attachment_image_src takes the url of the image, passing the id of the thumb as a parameter.

    
10.09.2015 / 13:00