WordPress.org

Make WordPress Core

Changeset 31388


Ignore:
Timestamp:
02/09/2015 07:26:56 PM (3 years ago)
Author:
jorbin
Message:

Use screen reader text instead of a title attribute in comments_popup_link

To better understand screen reader text, check out https://make.wordpress.org/accessibility/2015/02/09/hiding-text-for-screen-readers-with-wordpress-core/

Screen Reader text improves the user experience for screen reader users. It provides additional context for links, document forms and other pieces of a page that may exist visually, but are lost when looking only at the html of a site. This does change the output of comments_popup_link if you don't pass in values for $zero, $one, $more or $none. Theme authors can and should style <code>.screen-reader-text</code> in ways that are recommended in the above article to hide it visually.

Props joedolson
Fixes #26553

File:
1 edited

Legend:

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

    r31204 r31388  
    12751275
    12761276    $id = get_the_ID();
    1277 
    1278     if ( false === $zero ) $zero = __( 'No Comments' );
    1279     if ( false === $one ) $one = __( '1 Comment' );
    1280     if ( false === $more ) $more = __( '% Comments' );
    1281     if ( false === $none ) $none = __( 'Comments Off' );
    1282 
     1277    $span = '<span class="screen-reader-text">';
     1278    $title = get_the_title();
     1279    $span_close = '</span>';
     1280   
    12831281    $number = get_comments_number( $id );
     1282   
     1283    if ( false === $zero ) $zero = sprintf( __( 'No Comments%1$s on %2$s%3$s' ), $span, $title, $span_close );
     1284    if ( false === $one ) $one = sprintf( __( '1 Comment%1$s on %2$s%3$s' ), $span, $title, $span_close );
     1285    if ( false === $more ) $more = sprintf( __( '%4$d Comments%1$s on %2$s%3$s' ), $span, $title, $span_close, $number );
     1286    if ( false === $none ) $none = sprintf( __( 'Comments Off%1$s on %2$s%3$s' ), $span, $title, $span_close );
    12841287
    12851288    if ( 0 == $number && !comments_open() && !pings_open() ) {
     
    13121315        echo ' class="'.$css_class.'" ';
    13131316    }
    1314     $title = the_title_attribute( array('echo' => 0 ) );
    13151317
    13161318    $attributes = '';
     
    13241326    echo apply_filters( 'comments_popup_link_attributes', $attributes );
    13251327
    1326     echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
     1328    echo '>';
    13271329    comments_number( $zero, $one, $more );
    13281330    echo '</a>';
Note: See TracChangeset for help on using the changeset viewer.