Make WordPress Core


Ignore:
Timestamp:
01/12/2018 08:16:56 PM (7 years ago)
Author:
afercia
Message:

Accessibility: use aria-current for the paginated post links output by wp_link_pages().

Continues the introduction in core of the aria-current attribute after [41683], [41359], and [41371].

  • changes the wp_link_pages() (see the nextpage quicktag) output to use an aria-current attribute on the current item
  • adds post-nav-links and post-page-numbers CSS classes to help themes style these links
  • updates the related tests

Props antonioeatgoat, alexstine.
Fixes #41859.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-template.php

    r42343 r42440  
    863863 *
    864864 * @since 1.2.0
     865 * @since 5.0.0 Added the `aria_current` argument.
    865866 *
    866867 * @global int $page
     
    878879 *     @type string       $link_after       HTML or text to append to each Pages link inside the `<a>` tag.
    879880 *                                          Also appended to the current item, which is not linked. Default empty.
     881 *     @type string       $aria_current     The value for the aria-current attribute. Possible values are 'page',
     882 *                                          'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
    880883 *     @type string       $next_or_number   Indicates whether page numbers should be used. Valid values are number
    881884 *                                          and next. Default is 'number'.
     
    894897
    895898    $defaults = array(
    896         'before'           => '<p>' . __( 'Pages:' ),
     899        'before'           => '<p class="post-nav-links">' . __( 'Pages:' ),
    897900        'after'            => '</p>',
    898901        'link_before'      => '',
    899902        'link_after'       => '',
     903        'aria_current'     => 'page',
    900904        'next_or_number'   => 'number',
    901905        'separator'        => ' ',
     
    925929                if ( $i != $page || ! $more && 1 == $page ) {
    926930                    $link = _wp_link_page( $i ) . $link . '</a>';
     931                } elseif ( $i === $page ) {
     932                    $link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $r['aria_current'] ) . '">' . $link . '</span>';
    927933                }
    928934                /**
     
    10181024    }
    10191025
    1020     return '<a href="' . esc_url( $url ) . '">';
     1026    return '<a href="' . esc_url( $url ) . '" class="post-page-numbers">';
    10211027}
    10221028
Note: See TracChangeset for help on using the changeset viewer.