Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#47687 closed enhancement (fixed)

Use alt tags for gallery images in editor

Reported by: yarnboy's profile yarnboy Owned by: afercia's profile afercia
Milestone: 5.2.3 Priority: normal
Severity: normal Version: 5.2.2
Component: Media Keywords: has-patch needs-testing fixed-major
Focuses: accessibility, administration Cc:

Description

Gallery images do not include alt tag text in the WordPress editor. This presents a challenge for accessibility, and also adds a hurdle for writing plugins to force users to use alt tags (which is what I'm trying to do; I work for an institution that prioritizes web accessibility).

The solution to this problem is to make an edit to lines 1294 - 1302 in wp-includes/media-template.php, which currently appears this way:

							<# if ( attachment.thumbnail ) { #>
								<img src="{{ attachment.thumbnail.url }}" data-test="success" width="{{
								attachment
								.thumbnail.width }}" height="{{ attachment.thumbnail.height }}" alt="" />
							<# } else { #>
								<img src="{{ attachment.url }}" data-test="success" alt="" />
							<# } #>
							

And with my suggested edit:

							<# if ( attachment.thumbnail ) { #>
								<img src="{{ attachment.thumbnail.url }}" data-test="success" width="{{
								attachment
								.thumbnail.width }}" height="{{ attachment.thumbnail.height }}" alt="{{
								attachment.alt }}" />
							<# } else { #>
								<img src="{{ attachment.url }}" data-test="success" alt="{{ attachment.alt 
								}}" />
							<# } #>
							

Attachments (1)

47687.patch (869 bytes) - added by wpboss 5 years ago.
I have included alt tag text in the WordPress editor for the Gallery images

Download all attachments as: .zip

Change History (14)

@wpboss
5 years ago

I have included alt tag text in the WordPress editor for the Gallery images

#1 @wpboss
5 years ago

  • Keywords has-patch added

Hello, @yarnboy Thanks for the reported. I have added above patch as per your suggestion. Now alt tag text incleded in the WordPress editor for the Gallery images.

#2 follow-up: @afercia
5 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 5.3

@yarnboy @wpboss thanks the report and the patch!

Seems to me it's a good improvement for the Classic Editor. For the new Block Editor (Gutenberg), I see there's one more problem to solve. I'm going to report it on the Gutenberg GitHub repository.

Note for other reviewers: this relates to the alt attribute of gallery images within the editor.

#3 @wpboss
5 years ago

Thanks for the update @afercia.

So, Can I add same patch on https://github.com/WordPress/gutenberg/ or this patch will be auto included there?

#4 in reply to: ↑ 2 @yarnboy
5 years ago

Thanks @afercia! I'm pleased to have been able to contribute.

#5 @afercia
5 years ago

@wpboss the issue in Gutenberg is similar but the root cause is different, see https://github.com/WordPress/gutenberg/issues/16886. There's the need for a different approach there. If you're comfortable with Gutenberg development, please do feel free to propose a pull request!

#6 @afercia
5 years ago

  • Owner set to afercia
  • Resolution set to fixed
  • Status changed from new to closed

In 45725:

Accessibility: Fix the alt attribute of the Gallery images within the Classic Editor.

Passes the images alt attribute value to the Gallery template used within the Classic Editor.

Props yarnboy, wpboss.
Fixes #47687.

#7 @afercia
5 years ago

  • Keywords commit removed

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


5 years ago

#9 @audrasjb
5 years ago

  • Keywords needs-testing fixed-major added
  • Milestone changed from 5.3 to 5.2.3
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening this so it can be back-ported to the 5.2 branch.
Adding needs-testing since we have to check it's ok to land in 5.2.3.

#10 @audrasjb
5 years ago

Tested on my side against 5.2.2, but unless I'm mistaken [45725] doesn't look to apply cleanly: media-template.php seems to have some dependancies to previous commits. Otherwise, it's good to go.

#11 @JeffPaul
5 years ago

@afercia any insight into what commit(s) this may depend upon? If we're unsure, then we'll likely move this ticket back to 5.3. to limit risk in 5.2.3.

This ticket was mentioned in Slack in #core by marybaum. View the logs.


5 years ago

#13 @SergeyBiryukov
5 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 45865:

Accessibility: Fix the alt attribute of the Gallery images within the Classic Editor.

Passes the images alt attribute value to the Gallery template used within the Classic Editor.

Props yarnboy, wpboss.
Merges [45725] to the 5.2 branch.
Fixes #47687.

Note: See TracTickets for help on using tickets.