WordPress.org

Make WordPress Core

Changeset 46163


Ignore:
Timestamp:
09/18/2019 12:24:35 PM (2 months ago)
Author:
afercia
Message:

Accessibility: Add aria-current to the Archives, Categories, and Recent Posts widgets output.

The aria-current attribute is a simple, effective, way to help assistive technology users orientate themselves within a list of items.

Continues the introduction in core of the aria-current attribute after [41359] and following changes.

Props audrasjb, melchoyce.
Fixes #47094.

Location:
trunk/src/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-walker-category.php

    r46088 r46163  
    207207                    if ( $category->term_id == $_current_term->term_id ) {
    208208                        $css_classes[] = 'current-cat';
     209                        $link          = str_replace( '<a', '<a aria-current="page"', $link );
    209210                    } elseif ( $category->term_id == $_current_term->parent ) {
    210211                        $css_classes[] = 'current-cat-parent';
  • trunk/src/wp-includes/general-template.php

    r46154 r46163  
    17361736 */
    17371737function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) {
    1738     $text = wptexturize( $text );
    1739     $url  = esc_url( $url );
    1740 
    1741     if ( 'link' == $format ) {
     1738    $text         = wptexturize( $text );
     1739    $url          = esc_url( $url );
     1740    $aria_current = $selected ? ' aria-current="page"' : '';
     1741
     1742    if ( 'link' === $format ) {
    17421743        $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
    1743     } elseif ( 'option' == $format ) {
     1744    } elseif ( 'option' === $format ) {
    17441745        $selected_attr = $selected ? " selected='selected'" : '';
    17451746        $link_html     = "\t<option value='$url'$selected_attr>$before $text $after</option>\n";
    1746     } elseif ( 'html' == $format ) {
    1747         $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
     1747    } elseif ( 'html' === $format ) {
     1748        $link_html = "\t<li>$before<a href='$url'$aria_current>$text</a>$after</li>\n";
    17481749    } else { // custom
    1749         $link_html = "\t$before<a href='$url'>$text</a>$after\n";
     1750        $link_html = "\t$before<a href='$url'$aria_current>$text</a>$after\n";
    17501751    }
    17511752
  • trunk/src/wp-includes/widgets/class-wp-widget-recent-posts.php

    r43571 r46163  
    9494            <?php foreach ( $r->posts as $recent_post ) : ?>
    9595                <?php
    96                 $post_title = get_the_title( $recent_post->ID );
    97                 $title      = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
     96                $post_title   = get_the_title( $recent_post->ID );
     97                $title        = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
     98                $aria_current = '';
     99
     100                if ( get_queried_object_id() === $recent_post->ID ) {
     101                    $aria_current = ' aria-current="page"';
     102                }
    98103                ?>
    99104                <li>
    100                     <a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title; ?></a>
     105                    <a href="<?php the_permalink( $recent_post->ID ); ?>"<?php echo $aria_current; ?>><?php echo $title; ?></a>
    101106                    <?php if ( $show_date ) : ?>
    102107                        <span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span>
Note: See TracChangeset for help on using the changeset viewer.