-
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
Media & Text block: Remove the link option when the featured image is used #60510
Conversation
If the block is linked, insert the image inside the `a` tag, by replacing `</a>` with '<img></a>'. Otherwise, insert the image inside the `figure` tag.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
With this PR, if the featured image is linked but has no alt text, VoiceOver on Mac will read the URL is the link text. I think that is the best that can be done unless we want to add the "Link to post" setting (the same setting that the featured image block has). |
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.
Thanks for the PR!
I think the difficult part of this problem is finding the link of the featured image when the block contains multiple a
elements.
For example, when "Show media on the right" is enabled and a link exists in the content, the screenshot and the markup will look like this:
<!-- wp:media-text {"mediaPosition":"right","linkDestination":"custom","mediaType":"image","imageFill":false,"useFeaturedImage":true} -->
<div class="wp-block-media-text has-media-on-the-right is-stacked-on-mobile">
<div class="wp-block-media-text__content">
<!-- wp:paragraph {"placeholder":"Content…"} -->
<p>Hello <a href="#">World</a></p>
<!-- /wp:paragraph -->
</div>
<figure class="wp-block-media-text__media">
<a href="#test"></a>
</figure>
</div>
<!-- /wp:media-text -->
On the front end side, the following invalid markup is output:
<div class="wp-block-media-text has-media-on-the-right is-stacked-on-mobile">
<div class="wp-block-media-text__content">
<p>Hello
<a href="#">World
<img decoding="async" width="1024" height="683" alt="" class="wp-image-8 size-full" src="http://localhost:8888/wp-content/uploads/2024/04/test_1.jpg" srcset="http://localhost:8888/wp-content/uploads/2024/04/test_1.jpg 1024w, http://localhost:8888/wp-content/uploads/2024/04/test_1-300x200.jpg 300w, http://localhost:8888/wp-content/uploads/2024/04/test_1-768x512.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" />
</a>
</p>
</div>
<figure class="wp-block-media-text__media">
<a href="#test">
<img>
</a>
</figure>
</div>
I'm wondering how many users will want to take advantage of the custom link when they enable the featured image on this block. For example, when this block is inserted inside a Query Loop block and the link is enabled, I expect the featured image to automatically link to that post.
In any case, we need to find a way to detect the correct link. Ideally, it would be nice if we could specify the a
element inside the .wp-block-media-text__media
class, but as far as I know, WP_HTML_Tag_Processor
does not allow us to specify the parent element 😅
Thank you for lending me your brain!
|
This comment was marked as outdated.
This comment was marked as outdated.
index.php:
What is still missing:While I could add conditional options for changing the |
Thanks for the update!
This is because those attributes are not saved as HTML comments, but as part of the block HTML. If you remove the BTW, if I think about this problem again, it may be more difficult than I imagine. @draganescu @aaronrobertshaw I have summarized the problems and issues that I understand below, so if you have a good approach, please let me know 🙏
Considering these, I think the UI will probably look something like the following, what do you think? I'm concerned that the UI location for setting the link changes depending on whether the featured image is enabled or disabled. 54554e69874d98c8b21bc0be51ca3764.mp4 |
I have the same concerns. |
I opened this issue, but I'm not sure I described the problem clearly enough: |
If all blocks that use the featured image link option could move it to the link setting in the toolbar, it would be more consistent with how the "lightbox linking exception" works. I mean the exception where you can only choose one link or the other. But short term, what can we do to fix this rather large bug as soon as possible? |
I agree w/ @jasmussen about definitely not moving linking to the inspector - I think it would be a very isolated UX (an exception from how we generally link). I would also add that if we link to post what is the point of rel and target which make sense for external links? |
In #50893 I was thinking how link editing would consolidate across WordPress. It could be appended to the list in the link UI as pictured above, but I'd like to move forward on using LinkControl throughout the experience, to reduce ad hoc fixes/implementations. |
Yes I have intentionally avoided creating yet another custom and temporary link control. I still do think that this bug needs to be fixed and not get blocked. |
This pull request changed or added PHP files in previous commits, but none have been detected in the latest commit. Thank you! ❤️ |
Flaky tests detected in e0d8001. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9205311072
|
Is this solution acceptable until someone is able to re-work the LinkControl? What other options are there besides disabling the link settings or reverting the featured image option? I don't want this to go broken into 6.6. |
If the link option is disabled when the featured image is used, using the featured image in the media and text block inside a query is kind of pointless. |
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.
Given the feedback that ideally we move everything to the linking UI and since this is a bug fix what do y'all think if we just hide for now the linking option if the featured media image is used in the media text block?
I understand this reduces the usefulness of the featured image prop in the media text block, but it'd be a temporary solution that avoids yet another deprecation, and hundreds of documents updated when linking will happen in the toolbar.
I say this PR should only fix the bug and we then open a separate issue and PR to introduce link to post to link UI?
I'm not fully convinced that having the link option in the sidebar is more disruptive than not having a link option at all, but since this is the only feedback received I will try to update the PR so that this can be solved, short term. |
Remove functionality related to the link toggle option. Do not show the link option in the toolbar when the featured image is used. Reset the link option when an image that is linked is replaced with the featured image option. Without this reset, there is a link output on the front, in an incorrect position in the markup.
@carolinan I am not convinced either 100% 😁 but I lean towards removing linking altogether because the featured image prop of the media text block is new (will land in WP next), and we found a limitation of our linking system, so I generally default to less instead of more to undo later. |
I still want to test that there is no "weirdness" for people who has used Gutenberg and added links. |
For blocks that had the link set before this PR, the link is still output in the wrong position on the front:
Do I need to try to remove it? |
I would lean into no - using the plugin in production is precisely subject to these kinds of issues. #51491 introduced using the featured image for the media and text block which is a feature only available starting WP 6.6. If the bug landed in a WP release (minor or major) a minor release to remove this from where it was output (via some filter) would be justified. But since the bug existed only in the plugin, adding some logic to strip that out would be then shipped forever for a tiny fraction of cases. cc @Mamaduka is my reasoning above correct? |
@draganescu, yes, the reasoning makes sense. There is no need to introduce backward compatibility handers for code that has only ever existed in plugins. Also, if the content had been saved in DB, it would've been a different story, but IIRC, markup is dynamic for featured images. |
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.
This LGTM. Let's make an issue if it's not made to add "link to current post" the link UI somehow.
… used (WordPress#60510) * Media & Text block: Remove the link option when the featured image is used. When the Media & Text block uses the featured image and the link option, the block outputs invalid HTML. This change resolves the invalid markup on the front, by preventing users from adding the link using the toolbar option. Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: draganescu <andraganescu@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: richtabor <richtabor@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
… used (WordPress#60510) * Media & Text block: Remove the link option when the featured image is used. When the Media & Text block uses the featured image and the link option, the block outputs invalid HTML. This change resolves the invalid markup on the front, by preventing users from adding the link using the toolbar option. Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: draganescu <andraganescu@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: richtabor <richtabor@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
What & Why & How?
When the Media & Text block is linked and uses the featured image, the image is not linked on the front of the site.
Originally, this PR was meant to make the link work.
The preferred way to solve the bug, as expressed in the reviews below, would be to update the LinkControl component and replace ImageURLInputUI.
It was then recommended to solve the bug short-term by not showing the link option if the featured image is used, so that
the user can not use the broken control.
The PR was updated to reflect this.
Updated testing instructions:
Old description
The pull request updates where in the block markup the `img` tag is inserted:$content
contains an<a>
tag.<a>
tag, it inserts the<img>
tag by replacing the closing</a>
tag with<img></a>
.By replacing the closing
</a>
instead of the opening tag, the class names and attributes on the link are preserved.$content
does not contain a link, the<img>
tag is inserted directly inside the<figure>
.Closes #60497
Limitations
The PR does not address the problem that users can not set individual links on the block when it is placed inside a query loop.
Testing Instructions