Bootstrap : adding img-responsive class to thumbnail

I have to add img-responsive class to an image in wordpress page template.
My file is named as single-product.php.

This is my code

Read More
 <div class="col-md-6 col-xs-12" style="margin-top:35px;">
    <h1><?php the_title();?></h1>
  </div>
  <div class="col-md-6 col-xs-12">
   <?php  the_post_thumbnail();?>
 </div>

Now my question is how to add class to thumbnail?

Please assist me.

Related posts

3 comments

  1. the_post_thumbnail() takes two arguments, size and an array of attributes. one of the attributes you can set in the array is class, so an example would look like this

    <?php the_post_thumbnail( 'thumbnail', array( 'class' => 'img-responsive' ) ); ?>
    

    you may want to change thumbnail to the size you would like, or perhaps you can leave it blank. as always search the codex for the function in question and it normally has the answers https://codex.wordpress.org/Function_Reference/the_post_thumbnail

  2. Like this,

    <?php the_post_thumbnail( 'thumbnail', array( 'class' => 'img-responsive' ) ); ?>
    

    Also, it is not a good practice to use inline styles in your code.

Comments are closed.