Image Alt Text Not Displayed in HTML Despite Being Set in Media Library
-
I am using the Woodmart theme with Gutenberg to build my pages. I’ve noticed a recurring issue: although I set the alt text for each image during upload, the generated HTML on the front-end shows an empty alt=”” attribute.
Hi medmo,
Thanks for reaching to us.
Try to add the following PHP code snippet to the child theme functions.php file:
add_filter('wp_get_attachment_image_attributes', function ($attr, $attachment, $size) {
$id = $attachment->ID;
$alt = trim( strip_tags( get_post_meta( $id, '_wp_attachment_image_alt', true ) ) );
if ( $alt ) {
$attr['alt'] = $alt;
}
return $attr;
}, 10, 3);
Regards,
Hung PD
Hi there,
Same Problem. Please check the HP images to see the problem (made with Gutenberg editor)
Thanks
Hi medmo,
I created a test page https://bornesderecharge.ma/37275-2/ and alt are showing https://ibb.co/PGxDh8Bf
Regards,
Hung PD
Yes i know, the problem are only in elements Xtemos that use images in Gutenberg like slider, carrousel ….
Check the HP elements to understand better
Thank you,
-
This reply was modified 2 days, 11 hours ago by
medmo.
Hi medmo,
Please record a video that demonstrates the problem so we can understand and reproduce it on your website.
Kind Regards,
Hung PD
Here is 2 exemples in the Homepage (brand images, slider background), i added the alt texte in the backend, but when i check in the inspect element i dont found it,
Thanks
-
This reply was modified 1 day, 11 hours ago by
medmo.
Attachments:
You must be
logged in to view attached files.
Hi medmo,
Please make sure you added Alt
to images https://ibb.co/mrz36J5R > https://ibb.co/62m6GhX
Regards,
Hung PD
Thanks, but we dont have this field (image alt/title) in the Carroussel element or Slider element,
How to fix Alt texte for such elements ?
For exemple the slider background in the HP, the alt test not display i added it manuely in the media files but without success
Thanks,