WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.46k stars 4.18k forks source link

Media & text block: The Alt text for the featured image is not working correctly #60023

Closed carolinan closed 6 months ago

carolinan commented 7 months ago

Description

When the Media & text block uses a featured image, the alt text is:

  1. Pre-populated with the alt text from the media library, and can not be deleted or replaced from the alt text input field in the editor.
  2. Not present on the front.

Step-by-step reproduction instructions

With Gutenberg active: Create a new post and assign a featured image that has an alt text in the media library. Add a Media & text block and select the option "Use Featured image". Try to change the text in the block settings panel. Save and reload the post. Confirm that the alt text does not include the changes you made.

View the source of the block on the front of the site and confirm that there is no alt text output.

Screenshots, screen recording, code snippet

No response

Environment info

Gutenberg current trunk.

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

carolinan commented 7 months ago

@draganescu Hi, I am pinging you to ask for your continued help with this featured image feature.

I have not been able to fully solve this issue.

I can solve it partially by not using the alt text from the media library for the featured image. But then there are inconsistencies because it does not match how the alt text works for regular images. I made a draft PR here, it shows what I had to change, but I don't think it should be merged.

draganescu commented 7 months ago

Is this something that plagues the other "use featured image" enabled blocks (like cover)? Does the featured image block work?

carolinan commented 7 months ago

Cover and featured image blocks do not have alt text options.

t-hamano commented 6 months ago

I confirmed the approach you are trying in https://github.com/WordPress/gutenberg/pull/60029.

One thing to consider is that this block may be used inside a template or query loop block. For example, when used in a Single template, I don't think the alt text should be editable because the featured image changes dynamically depending on the post. Also, if it is inside a Query Loop block, I think the alt will be updated all at once.

Not present on the front.

In my opinion, it's better to just solve this problem first. In other words, similar to the Featured Image block, if "Use featured image" is enabled, the alt text control will be hidden, and the front end will always output the alt attribute of the media itself.

After that, we can explore approaches to make the alt text editable from a broader perspective, that is, the three blocks of the Featured Image block, Cover block, and Media & Text block, taking templates and query loop into consideration.

draganescu commented 6 months ago

if "Use featured image" is enabled, the alt text control will be hidden, and the front end will always output the alt attribute of the media itself.

This, I find this to be a predictable and good enough path.

carolinan commented 6 months ago

Yes, it is not great, but I had the same thought.

alexstine commented 6 months ago

Part of me wonders if we should fix the root problem here vs. adding a band-aid. Lots of work involved?

t-hamano commented 6 months ago

Lots of work involved?

I think so. Because the featured image changes dynamically depending on the context, Alt text data cannot be stored in the block markup or the comment delimiter. I think one approach would probably be to save it as a post meta with the definition "Alt text of the featured image in this post". I think this requires a lot of experimentation and verification.

alexstine commented 6 months ago

CC: @joedolson for any final feedback.

carolinan commented 6 months ago

There is one more known issue that will need to be fixed besides removing the alt text option and fixing the missing link. When the featured image is linked and there is no alt text, there is no link text. I have not opened the PR for that yet but I plan to.