[wp-trac] [WordPress Trac] #63020: HTML API: Breadcrumbs should include element indices and attributes

WordPress Trac noreply at wordpress.org
Tue Sep 2 12:00:31 UTC 2025


#63020: HTML API: Breadcrumbs should include element indices and attributes
-------------------------+---------------------
 Reporter:  westonruter  |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  6.9
Component:  HTML API     |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+---------------------
Changes (by ibrahimhajjaj):

 * keywords:  needs-patch => has-patch


Comment:

 I added `get_element_breadcrumbs()` to `WP_HTML_Processor`. It gives
 detailed breadcrumbs with element indices and key attributes (id, role,
 class) that the Optimization Detective plugin uses for XPath generation.

 Each breadcrumb in the returned array includes:

 * tag name
 * namespace (html/svg/math)
 * sibling index
 * relevant attributes for disambiguation

 I also added a full test suite—11 cases covering basics, indexing, deep
 nesting, attributes, and edge cases. Everything passes.

 This should make it way easier to generate unambiguous XPaths without
 subclassing `WP_HTML_Tag_Processor` like Optimization Detective does now.

 Implementation is in `src/wp-includes/html-api/class-wp-html-
 processor.php`, tests in `tests/phpunit/tests/html-
 api/wpHtmlProcessorElementBreadcrumbs.php`.

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


More information about the wp-trac mailing list