Opened 6 years ago
Closed 6 years ago
#46291 closed defect (bug) (fixed)
Twenty Nineteen: Avoid nested links in comment meta section of the comment in TwentyNineteen_Walker_Comment class
Reported by: | iamdmitrymayorov | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.2 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Bundled Theme | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
Description
If a user adds his URL when leaving a comment, his avatar and name becomes a link to the URL he provided. It appears though that there is a bug in TwentyNineteen_Walker_Comment
class that produces a markup with nested links in this case. This is how the output markup looks like:
<div class="comment-author vcard"> <a href="https://wordpress.org/" rel="external nofollow" class="url"><img alt='' src='...' srcset='... 2x' class='avatar avatar-60 photo' height='60' width='60' /> <b class="fn"><a href='https://wordpress.org/' rel='external nofollow' class='url'>A WordPress Commenter</a></b> <span class="screen-reader-text says">says:</span> </a> </div><!-- .comment-author -->
And if you inspect the code in Chrome, it gets even funkier. Chrome automatically closes the first link tag and adds an empty <b class="fn"></b>
inside:
https://monosnap.com/file/HjGPfmwFKO4fUxUl0Avl7ExMTnlr4w#embed
I understand original idea: put an image and an author name inside one link tag, which is a valid HTML5 markup.
However it doesn't work because get_comment_author_link()
is used to output the comment author name. This function falls back to get_comment_author()
if there is no URL, but in our case it breaks the markup when the URL is present.
We can easily fix it by using get_comment_author()
instead. The comment author name will still be clickable and focusable because it will be inside the link tag.
Attachments (3)
Change History (10)
#3
@
6 years ago
Thanks for the update @mukesh27. This actually brings me to another minor observation. $comment_author_link
becomes useless if this gets merged. In fact, it was unused before, but I think it was just an oversight, because the link was actually outputted inside the <b>
tag. Anyway, there is probably no point in keeping that variable there.
Hi @iamdmitrymayorov, Welcome to WordPress Trac! Thank you for your ticket.
Good cache.
Updated patch as theme already define variable for that function
$comment_author = get_comment_author( $comment );
so just needs to use that variable instead of add another call ofget_comment_author( $comment )
function.