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 git-svn-id: https://develop.svn.wordpress.org/trunk@31388 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d5888fbc13
commit
cf09359d34
@ -1274,13 +1274,16 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
|
|||||||
global $wpcommentspopupfile, $wpcommentsjavascript;
|
global $wpcommentspopupfile, $wpcommentsjavascript;
|
||||||
|
|
||||||
$id = get_the_ID();
|
$id = get_the_ID();
|
||||||
|
$span = '<span class="screen-reader-text">';
|
||||||
if ( false === $zero ) $zero = __( 'No Comments' );
|
$title = get_the_title();
|
||||||
if ( false === $one ) $one = __( '1 Comment' );
|
$span_close = '</span>';
|
||||||
if ( false === $more ) $more = __( '% Comments' );
|
|
||||||
if ( false === $none ) $none = __( 'Comments Off' );
|
|
||||||
|
|
||||||
$number = get_comments_number( $id );
|
$number = get_comments_number( $id );
|
||||||
|
|
||||||
|
if ( false === $zero ) $zero = sprintf( __( 'No Comments%1$s on %2$s%3$s' ), $span, $title, $span_close );
|
||||||
|
if ( false === $one ) $one = sprintf( __( '1 Comment%1$s on %2$s%3$s' ), $span, $title, $span_close );
|
||||||
|
if ( false === $more ) $more = sprintf( __( '%4$d Comments%1$s on %2$s%3$s' ), $span, $title, $span_close, $number );
|
||||||
|
if ( false === $none ) $none = sprintf( __( 'Comments Off%1$s on %2$s%3$s' ), $span, $title, $span_close );
|
||||||
|
|
||||||
if ( 0 == $number && !comments_open() && !pings_open() ) {
|
if ( 0 == $number && !comments_open() && !pings_open() ) {
|
||||||
echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
|
echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
|
||||||
@ -1311,7 +1314,6 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
|
|||||||
if ( !empty( $css_class ) ) {
|
if ( !empty( $css_class ) ) {
|
||||||
echo ' class="'.$css_class.'" ';
|
echo ' class="'.$css_class.'" ';
|
||||||
}
|
}
|
||||||
$title = the_title_attribute( array('echo' => 0 ) );
|
|
||||||
|
|
||||||
$attributes = '';
|
$attributes = '';
|
||||||
/**
|
/**
|
||||||
@ -1323,7 +1325,7 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
|
|||||||
*/
|
*/
|
||||||
echo apply_filters( 'comments_popup_link_attributes', $attributes );
|
echo apply_filters( 'comments_popup_link_attributes', $attributes );
|
||||||
|
|
||||||
echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
|
echo '>';
|
||||||
comments_number( $zero, $one, $more );
|
comments_number( $zero, $one, $more );
|
||||||
echo '</a>';
|
echo '</a>';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user