I’m trying to update my company’s website to be more ADA friendly by ensuring all images have alt-text assigned. However, when I add alt text on the WordPress CMS, I’m not able to view it in the HTML.
Please see attached screenshots for reference.
I would greatly appreciate any help that any one can give me on where to look on the server and what to add to ensure that my alt-text will be displayed.
This is the code snippet for the icon I reference in the screenshot:
<img data-src="https://applecareurgentcare.com/wp-content/uploads/2020/04/apple-care-laptop.png" class=" lazyloaded" src="https://applecareurgentcare.com/wp-content/uploads/2020/04/apple-care-laptop.png">
Screen shot of alt text added in wordpress media library
2
Answers
Well there are two ways of doing this, when you have the attachment ID. I am going to answer with the best and recommended way.
Use the function
wp_get_attachment_image
from WordPress core.You can use it in this way.
Where
49
is theid
of theimage
and andthumbnail
is the size.Output:
Benefits of it.
alt
text for your attachment.loading="lazy"
which is a recent update in WordPress.srcset
.If you added the Alt-text to the image in the Media Library after the image was already inserted into the page, then the Alt-text will not update on the image on the page. You would need to reinsert the image or go to the page it appears on and add alt="" with the Alt-text inside that, adding it in code view.