Skip to content
Advertisement

Empty alt tags wordpress

I’m using WordPress with Listingpro template, I’ve been looking around for a solution and I’ve found the following:

// An attachment/image ID is all that's needed to retrieve its alt and title attributes.
$image_id = get_post_thumbnail_id();    
$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE);  
$image_title = get_the_title($image_id);

But, when I add this alt='$image_alt' showed me an empty alt.

Advertisement

Answer

<img src="whatever-src" alt="'.$image_alt.'">

This is what you need, when it is inside echo. Only if there is any alt associated with that image.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement