Accessibility: Widgets: Conditionally wrap the tag cloud widget in a <nav>
element.
If the theme declares support for the `html5` feature `navigation-widgets`, the tag cloud widget is now wrapped in a `<nav>` element to improve semantics and accessibility. The `<nav>` elements are native landmark regions, which helps assistive technology users to navigate through them. Follow-up to [48349] for other widgets. Props audrasjb, justinahinon, ravipatel. Fixes #51455. See #48170. git-svn-id: https://develop.svn.wordpress.org/trunk@49177 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f3f2aa135e
commit
0f6305e246
@ -90,11 +90,28 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
|
||||
echo $args['before_title'] . $title . $args['after_title'];
|
||||
}
|
||||
|
||||
$format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
|
||||
|
||||
/** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */
|
||||
$format = apply_filters( 'navigation_widgets_format', $format );
|
||||
|
||||
if ( 'html5' === $format ) {
|
||||
// The title may be filtered: Strip out HTML and make sure the aria-label is never empty.
|
||||
$title = trim( strip_tags( $title ) );
|
||||
$aria_label = $title ? $title : $default_title;
|
||||
echo '<nav role="navigation" aria-label="' . esc_attr( $aria_label ) . '">';
|
||||
}
|
||||
|
||||
echo '<div class="tagcloud">';
|
||||
|
||||
echo $tag_cloud;
|
||||
|
||||
echo "</div>\n";
|
||||
|
||||
if ( 'html5' === $format ) {
|
||||
echo '</nav>';
|
||||
}
|
||||
|
||||
echo $args['after_widget'];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user