1

I'm using the following to output the post thumbnail as a marker on a map.

$thumb_id = get_post_thumbnail_id();
$thumb_url_array =  wp_get_attachment_image_src($thumb_id, array( 100, 100), true);
$thumb_url = $thumb_url_array[0];

But, I want to add a class to the thumbnail.

I tried array('class' => 'your-class-name') but that didn't work.

0

Use wp_get_attachment_image() instead if you want to set a class property.

Example:

$image = wp_get_attachment_image(
    get_post_thumbnail_id(), 
    array(100, 100), 
    true, 
    array('class' => 'your-class-name')
);

//returns the HTML for the attachment
echo $image; 

The above function returns the HTML img tag:

<img src="http://example.com/path/to/image.jpg" class="your-class-name"/>

You can see the difference between functions here:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.