Make WordPress Core

Ticket #51455: 51455.diff

File 51455.diff, 1.1 KB (added by audrasjb, 4 years ago)

Accessibility: Widgets: Add theme support to make tag cloud widget output list of links wrapped within a <nav> element.

  • src/wp-includes/widgets/class-wp-widget-tag-cloud.php

    diff --git a/src/wp-includes/widgets/class-wp-widget-tag-cloud.php b/src/wp-includes/widgets/class-wp-widget-tag-cloud.php
    index c23cda21f1..8b5c4a80b9 100644
    a b class WP_Widget_Tag_Cloud extends WP_Widget { 
    9090                        echo $args['before_title'] . $title . $args['after_title'];
    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
    95107                echo $tag_cloud;
    96108
    97109                echo "</div>\n";
     110
     111                if ( 'html5' === $format ) {
     112                        echo '</nav>';
     113                }
     114
    98115                echo $args['after_widget'];
    99116        }
    100117