elementor / elementor/elementor

Media Control get_image_alt function returns unhelpful fallbacks

Open
#13,404 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
7.1k
Forks
1.6k
Avg merge
1d 5h
Merged PRs (30d)
193

Description

## Prerequisites

- [x] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- [x] The issue still exists against the latest stable version of Elementor.

## Description

When an image has no alternative text defined `Control_Media::get_image_alt( $instance )` returns either the description or the title. If the user hadn't bothered to insert alternative text isn't it pretty likely they hadn't bothered to insert a title or description either? Seeing as by default WordPress sets the file name as the media title this seems harmful to accessibility: the file name would be read to screen reader users, when file names very rarely make for good descriptors and are often gibberish. This might not be great for SEO either.

Why does this function use fallbacks when there is a dedicated field for alternative text? Why does it behave differently in this regard than wp_get_attachment_image would?
https://github.com/elementor/elementor/blob/04b62eb0fe6df9c035b1a31b72e67b8babd4ba5e/includes/controls/media.php#L269-L276
This function isn't used by your code a whole lot, but I've used it in my own widgets and I'm thinking that might've been a mistake.

In Image Box you use it to render attributes you then never "get" because the HTML is rendered by `get_attachment_image_html` instead.
https://github.com/elementor/elementor/blob/04b62eb0fe6df9c035b1a31b72e67b8babd4ba5e/includes/widgets/image-box.php#L548-L557
and in `get_attachment_image_html` you only use it when not in static render mode, I'm not sure what/when that is.
https://github.com/elementor/elementor/blob/04b62eb0fe6df9c035b1a31b72e67b8babd4ba5e/includes/controls/groups/image-size.php#L99-L121
The only element where I could see the fallback in action on my test site is the Image Carousel.
https://github.com/elementor/elementor/blob/04b62eb0fe6df9c035b1a31b72e67b8babd4ba5e/includes/widgets/image-carousel.php#L698

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.