Ever wanted to add a class to the Featured Image (a.k.a. Post Thumbnail)? This snippet will add an extra class to the post thumbnail in a theme template.
Instructions
Add this snippet inside the loop of a WordPress theme template.
if ( has_post_thumbnail() ) { the_post_thumbnail('medium', array('class' => 'alignleft')); }
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our WPtouch Review.
this doesn’t work, this REPLACES the set of classes by your own
Hi How can i add a div as parent element to the image? thanks
You won’t be able to with the code above. However you could do the following
if ( has_post_thumbnail() ) {
echo '';
}
Where should I paste the code sire
Thank you, it’s working 🙂
saved my day!!! Thank you
Thank you 😉 I was looking for it 😉
Happy new year!
Thx a lot!! This is what I was looking for!!
Thx a lot!! This is what I was lokking for!!