Home › Forums › WoodMart support forum › Image Alt Text Not Displayed in HTML Despite Being Set in Media Library

Image Alt Text Not Displayed in HTML Despite Being Set in Media Library

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #675171

    medmo
    Participant

    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.

    #675246

    Hung Pham
    Participant

    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

    #675274

    medmo
    Participant

    Hi there,

    Same Problem. Please check the HP images to see the problem (made with Gutenberg editor)

    Thanks

    #675293

    Hung Pham
    Participant

    Hi medmo,

    I created a test page https://bornesderecharge.ma/37275-2/ and alt are showing https://ibb.co/PGxDh8Bf

    Regards,
    Hung PD

    #675296

    medmo
    Participant

    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 1 year, 2 months ago by medmo.
    #675432

    Hung Pham
    Participant

    Hi medmo,

    Please record a video that demonstrates the problem so we can understand and reproduce it on your website.

    Kind Regards,
    Hung PD

    #675497

    medmo
    Participant

    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 year, 2 months ago by medmo.
    Attachments:
    You must be logged in to view attached files.
    #675656

    Hung Pham
    Participant

    Hi medmo,

    Please make sure you added Alt to images https://ibb.co/mrz36J5R > https://ibb.co/62m6GhX

    Regards,
    Hung PD

    #675744

    medmo
    Participant

    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,

    #675939

    Hung Pham
    Participant

    Hi medmo,

    You need to fill the Alt into images directly.

    Regards,
    Hung PD

Viewing 10 posts - 1 through 10 (of 10 total)