Mabero
Mabero

Reputation: 57

How can I make Featured Image/Thumbnail responsive?

I'm looking for some code to make the thumbnail of my images responsive in the way that they resize when I resize my browser if that makes sense. So I found this code and it kind of works:

if ( has_post_thumbnail() ) {
    $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),’thumbnail’ );
    echo '<img width="100%" src="' . $image_src[0] . '">';
}

The only problem is that it gives me this error:

Warning: Use of undefined constant ’thumbnail’ - assumed '’thumbnail’'

(this will throw an Error in a future version of PHP)

So what I'm wondering is if there is a new way to do this.

Thanks!

Upvotes: 1

Views: 201

Answers (1)

Krupal Panchal
Krupal Panchal

Reputation: 1545

It looks like you have copied this code from somewhere else.

So in $image_src image size thumbnail have copied Single Quotes.

Remove that Quotes and try the default editor's Single or Double quote and try again.

Upvotes: 1

Related Questions