mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-16 18:44:32 +00:00
Accessibility: Widgets: Add theme support to make widgets output list of links wrapped within a <nav> element.
Widgets that output list of links can now be wrapped within `<nav>` elements to improve semantics and accessibility. The `<nav>` elements are also native landmark regions, which helps assistive technology users to navigate through them. Themes can opt-in to this new behavior by declaring support for the new `html5` feature `navigation-widgets`. Props joedolson, simonjanin, audrasjb, afercia. Fixes #48170. git-svn-id: https://develop.svn.wordpress.org/trunk@48349 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -82,7 +82,8 @@ class WP_Widget_Recent_Comments extends WP_Widget {
|
||||
|
||||
$output = '';
|
||||
|
||||
$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments' );
|
||||
$default_title = __( 'Recent Comments' );
|
||||
$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : $default_title;
|
||||
|
||||
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
|
||||
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
|
||||
@@ -123,6 +124,25 @@ class WP_Widget_Recent_Comments extends WP_Widget {
|
||||
$recent_comments_id = ( $first_instance ) ? 'recentcomments' : "recentcomments-{$this->number}";
|
||||
$first_instance = false;
|
||||
|
||||
$format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
|
||||
|
||||
/**
|
||||
* Filters the HTML format of widgets with navigation links.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @param string $format The type of markup to use in widgets with navigation links.
|
||||
* Accepts 'html5', 'xhtml'.
|
||||
*/
|
||||
$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;
|
||||
$output .= '<nav role="navigation" aria-label="' . esc_attr( $aria_label ) . '">';
|
||||
}
|
||||
|
||||
$output .= '<ul id="' . esc_attr( $recent_comments_id ) . '">';
|
||||
if ( is_array( $comments ) && $comments ) {
|
||||
// Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
|
||||
@@ -141,6 +161,11 @@ class WP_Widget_Recent_Comments extends WP_Widget {
|
||||
}
|
||||
}
|
||||
$output .= '</ul>';
|
||||
|
||||
if ( 'html5' === $format ) {
|
||||
$output .= '</nav>';
|
||||
}
|
||||
|
||||
$output .= $args['after_widget'];
|
||||
|
||||
echo $output;
|
||||
|
||||
Reference in New Issue
Block a user