Closed carolinan closed 6 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.
Is this something that plagues the other "use featured image" enabled blocks (like cover)? Does the featured image block work?
Cover and featured image blocks do not have alt text options.
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.
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.
Yes, it is not great, but I had the same thought.
Part of me wonders if we should fix the root problem here vs. adding a band-aid. Lots of work involved?
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.
CC: @joedolson for any final feedback.
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.
Description
When the Media & text block uses a featured image, the alt text is:
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