WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 7 weeks ago

#46747 assigned defect (bug)

Recent Comments widget can add duplicate ID to page

Reported by: mbrailer Owned by: audrasjb
Milestone: 5.3 Priority: normal
Severity: normal Version: 5.1
Component: Widgets Keywords: needs-dev-note has-patch commit
Focuses: Cc:

Description

The Recent Comments widget includes the markup <ul id="recentcomments">

When more than one instance of the widget is used in a page, the ID appears multiple times, which is invalid according to W3.

Attachments (2)

46747.diff (737 bytes) - added by justinahinon 4 months ago.
Change the hard coded widget ID of recent comments widget
46747.1.diff (810 bytes) - added by audrasjb 7 weeks ago.
Dissociate aside and ul elements IDs

Download all attachments as: .zip

Change History (9)

#1 @audrasjb
5 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.3
  • Owner set to audrasjb
  • Status changed from new to accepted

Hi @mbrailer welcome to WordPress Core Trac and many thanks for opening that ticket!

I'm able to reproduce the issue. Moving it to 5.3 milestone :-)

Cheers,
Jb

#2 @justinahinon
4 months ago

  • Keywords has-patch added; needs-patch removed

Change the hard coded widget ID

@justinahinon
4 months ago

Change the hard coded widget ID of recent comments widget

#3 @audrasjb
4 months ago

  • Keywords needs-dev-note added
  • Status changed from accepted to assigned

Thanks for the patch @justinahinon

The patch looks fine on my side. Adding a needs-dev-note tag to handle backward compatibility for theme authors.

#4 @birgire
4 months ago

ps: I was just wondering if the widget_id argument can be changed via some filter?

I didn't find a way, by quickly skimming through the widget code for WP_Widget_Recent_Comments and WP_Widget, but just wanted to be sure :-)

If we find a way then I think we should escape it with esc_attr().

#5 @audrasjb
7 weeks ago

  • Keywords needs-refresh added; has-patch removed
  • Severity changed from minor to normal

Hi,

There is an issue with the last patch. In several themes, we still have duplicate IDs. Not when two widgets are used, but inside the code of each widget.

Here is an example of HTML output with twenty eleven:

aside and ul elements have the same id.

<aside id="recent-comments-2" class="widget widget_recent_comments">
    <h3 class="widget-title">Commentaires récents</h3>
    <ul id="recent-comments-2" class="recentcomments"></ul>
</aside>

@audrasjb
7 weeks ago

Dissociate aside and ul elements IDs

#6 @audrasjb
7 weeks ago

  • Keywords has-patch added; needs-refresh removed

46747.1.diff is fixing the issue.

I also drafted a dev note to inform Theme Authors: https://docs.google.com/document/d/1y5yZSwqHcFjA3aioUusEOxotbBOyGjQqPLwYC4oY2Kc/edit?usp=sharing

#7 @audrasjb
7 weeks ago

  • Keywords commit added
Note: See TracTickets for help on using tickets.