This seems to be an easy one but its giving me quite a hard time. get_the_post_thumbnail() suppose to take attribute as an array. Well, everything working right but when i pass style attr its doesn’t work.
$attr = array(
'title' => get_the_title(),
'alt' => get_the_title(),
'style' => 'float:left'
);
$thumb = get_the_post_thumbnail($post->ID, 'large-thumb', $attr);
The title and the alt attribute is set up nicely though but style attribute is missing in images.
FYI: I am showing the thumbnail in rss feed.
get_the_post_thumbnail
attribute array doesn’t knowSTYLE
, the fields that are available for you to use are:src
class
alt
title
so just use the class and define you class to it:
and then define the style in the class:
Update:
My bad rss feed can really be styled like HTML since its not HTML. so to over come this problem you need to have your image inside the content tag and give it an align=”left” which should work in most rss readers.
so what you really want is to add a content_filter:
I stumbled on a good and more global solution for this on Isabel Castillo’s blog, by using
wp_get_attachment_image_attributes
filter:This way, you could add other attributes as well (e.g.
data-caption
)Original code on http://isabelcastillo.com/add-title-attribute-wordpress-image-thumbnail