CP should set automatic ALT tags based on the file name for all images that do not have ALT tag saved in the database. This kills 2 birds with one stone:
I’m not sure it improves either unless the image name is meaningful, does it?
Not every file name would make a great ALT tag, but file names tend to have some valuable information. A lot of people choose to use a descriptive file names, and if they do include keywords they can benefit SEO.
Plus, on accessibility part, having something in ALT tag is better than nothing. Screen readers can't read empty ALT tags, but if something is in there it does help user get a little better understanding of what it is.
Beyonce got sued by blind user, one of the issues cited "One of her complaints is that the pictures, which are an important feature of the website, lack a text alternative that can be read out by a screen-reader used by the unsighted, as required by U.S. law."https://calgaryherald.com/entertainment/celebrity/beyonce-sued-by-blind-woman-over-website-accessibility/wcm/3a6504cf-8495-49b1-8373-1520fc3e79dd
Sure, having automatic ALT tags isn't perfect since file names can be generic. But having them is better than not having them at all.
I think having alt tags filled in automatically would create the danger of making things worse. Imagine the situation of a blind reader who is told that this is, for example, a1becdddjf because that happens to be the file name before the file extension.
What would be much better would be something like an automatic prompt to fill in the alt tag whenever an image is uploaded. But even that has its problems, because (a) it wouldn't catch images uploaded from outside of WP/CP and then somehow linked, and (b) not all images should have alt tags.
If the image exists purely for aesthetic reasons and conveys no meaning at all, then it is perfectly legitimate to "hide" it from screenreaders using code like this: role='presentation' aria-hidden='true'. In such cases the alt tag should be left blank.
Typical users don't set ALT tags, roles or aria attributes. Majority of images uploaded through media library are used in posts/pages and are not decorative.
If we do want to prompt user to add ALT tag, we can also give them an option to check "Decorative use only", which would set appropriate role/aria.
From WebAIM on alt text:"Every image must have an alt attribute. This is a requirement of HTML standard (with perhaps a few exceptions in HTML5). Images without an alt attribute are likely inaccessible. In some cases, images may be given an empty or null alt attribute (e.g., alt="")."
If image has an empty alt tag, screen readers ignore it completely. If image doesn't have an alt tag attribute, screen reader will say "image".
Again, it's not perfect but for majority of the cases it will be an improvement. Far better than to do nothing as it is now in WordPress.
It's similar to how WordPress enables automatic updates for minor versions for all to try and accommodate typical users who don't update. But, if you know what you're doing you can customize automatic updates to turn them off or change how it behaves.
I'd suggest "semi-automatic" alt tags, ARIA / role assignments for auto-generated image tags, eg. wp_get_attachment, the_thumbnail and the likes, using a specific option. Maybe even a small separate Accessibility settings page.
I agree with Tim's concern regarding filenames. The principle of improved SEO is sound, but in more than 10 years of working with WordPress, I've seen far more images with meaningless names like DSC_34243.jpg, IMAG20180323.jpg, SANY43234.jpg... using these for alt attributes would be a mistake. Personally, I don't think auto-alt-tag should be a core feature, but I wouldn't mind if, say, the site title was used for the alt value in cases where it is missing. That won't necessarily further accessibility, but neither will it hinder SEO.
>If image doesn't have an alt tag attribute, screen reader will say "image".
That's bad enough, of course, but unfortunately it's not always true either. Some screenreaders will then read out the whole URL of the image. In such cases the code I provided will save the reader from that silliness. And you'll note that that code has two parts because some screenreaders will follow one, while some will follow the other. (It's just like the old browser wars.)
>If we do want to prompt user to add ALT tag, we can also give them an option to check "Decorative use only", which would set appropriate role/aria.
I could get behind this idea.
Auto-generated alt tags are rarely a good idea. As others have stated, the screen reader output would be unreliable, plus there would have to be regex considerations for filenames with underscores, hyphens, etc. The point of alt tags is to describe the image, which should happen in a sentence, not a word or a filename, and I can't imagine any way this would work reliably. I appreciate the sentiment of accessibility, but a method like this would do more harm than good.
What might work well is to make ALT tag required, unless user checks an option I suggested above "Decorative use only". We could offer a suggestion based on the filename, but if ALT tag is required that wouldn't be necessary.
making ALT tags required does not work either. Look at accessibility guideline "IF" an image is purely decoration and rpovides no meaning you can leave it blank. What about a profile pic? Again guidelines suggest if someon'e name proceeds the picture there is no reason to put the name in the alt text as it is is redundant.
If the alt tag is missing would it not be better to simply use the post title as the alt tag since images are normally related to the post?