[wp-trac] [WordPress Trac] #65315: Inserting the same image with different captions on the same page results in figcaptions with duplicate `id` elements.

WordPress Trac noreply at wordpress.org
Fri May 22 08:45:30 UTC 2026


#65315: Inserting the same image with different captions on the same page results
in figcaptions with duplicate `id` elements.
--------------------------------------+------------------------------
 Reporter:  SteelWagstaff             |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  Media                     |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  accessibility
--------------------------------------+------------------------------

Comment (by SteelWagstaff):

 PR: https://github.com/WordPress/wordpress-develop/pull/11940/

 Summary of problem:
 When an image is inserted with a caption, WordPress creates a [caption
 id="attachment_123"] shortcode
 When rendered, this generates:
 Figure element: <figure id="attachment_123">
 Figcaption element: <figcaption id="caption-attachment-123">

 If the same image (same attachment ID) is used multiple times with
 different captions, all figcaptions get the same ID, violating the
 uniqueness requirement for ID attributes within HTML documents
 ([https://html.spec.whatwg.org/multipage/dom.html#element-attrdef-global-
 id:~:text=When%20specified%20on%20HTML%20elements%2C%20the%20id%20attribute%20value%20must%20be%20unique%20amongst%20all%20the%20IDs%20in%20the%20element%27s%20tree%20and%20must%20contain%20at%20least%20one%20character.%20The%20value%20must%20not%20contain%20any%20ASCII%20whitespace
 source])

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/65315#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list