WordPress.org

Make WordPress Core

Changeset 49177


Ignore:
Timestamp:
10/16/2020 06:30:53 PM (9 days ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-tag-cloud.php

    r47593 r49177  
    9191        }
    9292
     93        $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
     94
     95        /** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */
     96        $format = apply_filters( 'navigation_widgets_format', $format );
     97
     98        if ( 'html5' === $format ) {
     99            // The title may be filtered: Strip out HTML and make sure the aria-label is never empty.
     100            $title      = trim( strip_tags( $title ) );
     101            $aria_label = $title ? $title : $default_title;
     102            echo '<nav role="navigation" aria-label="' . esc_attr( $aria_label ) . '">';
     103        }
     104
    93105        echo '<div class="tagcloud">';
    94106
     
    96108
    97109        echo "</div>\n";
     110
     111        if ( 'html5' === $format ) {
     112            echo '</nav>';
     113        }
     114
    98115        echo $args['after_widget'];
    99116    }
Note: See TracChangeset for help on using the changeset viewer.