-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the post-title as the featured-image's alt text when linked to the post #39634
Conversation
Size Change: +1.78 kB (0%) Total Size: 1.21 MB
ℹ️ View Unchanged
|
The code looks good. The post title won't always match the description of the featured image, but it might be preferable over missing alt text. /cc @alexstine |
Agreed. Since it's a link to the post and not the image, it makes more sense to use the post-title and not the image's alt text. |
Matches guidelines by w3.org:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good, and the change matches the official specs.
It would be nice to get second approval from folks with more experience in a11y.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added one A11Y thought. Please feel free to explain this to me differently if I misunderstood.
@aristath Overall, this is a super simple but helpful change. Thanks for your work on this. Especially in the front-end context. 👍 |
@alexstine I made the suggested edits on the alt-text for the editor, so I'll ahead and merge this one. |
What?
Use the post-title as the alt-text of a featured image, when that image links to the post.
Why?
We use
get_the_post_thumbnail()
to get the post-thumbnail, and display it. That function callswp_get_attachment_image()
to generate the HTML. The problem here, is thatwp_get_attachment_image
uses the image's metadata to get the alt-text. As a result of that, assistive technologies announce the image's alt text (if one even exists) for the link, and that is not what it should be.The link points to the post, and therefore should have the post-title as alt description, instead of the image's alt description. The image does not describe the link, the post-title does.
How?
Added a 3rd argument to the
get_the_post_thumbnail()
call, defining thealt
attribute as the post-title.Testing Instructions
In the twentytwentytwo theme, add a post with a featured image, and then confirm that on the frontpage the post-title is used as the image's alt text when the post-thumbnail is a link to the post itself.