I am using the following piece of code to grab the featured images of posts by category. The code uses the echo statement to add the img tag for the featured image to the website.

if (has_post_thumbnail($post->ID)) {
        $retina  = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'homepage-thumb-retina' );
        echo '<img src="' . $retina[0] . '" alt="' . the_title() .'"   width="300" height="150" /> <br/>' ;
};

The contents of the alt attribute is getting rendered as plain text on the website. I am new to php and wordpress, so I assume there is something wrong with the syntax.

Any help is appreciated.

Read more here: WordPress – contents of alt attribute getting rendered as plain text on website


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: