Mobile app version of vmapp.org
Login or Join
Deb1703797

: Correct method for styling screen reader page text? The following markup is rendered by WordPress’ the_posts_pagination(): <nav class="navigation pagination" role="navigation"> <h2 class="screen-reader-text">Posts

@Deb1703797

Posted in: #Accessibility #HiddenText #Navigation

The following markup is rendered by WordPress’ the_posts_pagination():

<nav class="navigation pagination" role="navigation">
<h2 class="screen-reader-text">Posts navigation</h2>
<div class="nav-links">
<span class="page-numbers current"><span class="meta-nav screen-reader-text">Page </span>1</span>
<a class="page-numbers" href="http://example.com/blog/page/2/"><span class="meta-nav screen-reader-text">Page </span>2</a>
<a class="next page-numbers" href="http://example.com/blog/page/2/">Next page</a>
</div>
</nav>


Is it bad practice to use css to hide the screen reader text which prints 'Posts navigation' above these links? Or if I hide it in a media query for large screens is that acceptable?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Deb1703797

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ravi8258870

It is not always advisable to hide output with CSS as that output is still view-able in the browser console, but in this case, the only option is with CSS.

If you take a look at the source code for the_posts_pagination(), you will see that it simply echos the output from get_the_posts_pagination(). If you look into the source code, you'll see that this is basically just a wrapper function for paginate_links().

Not to get carried away here, get_the_posts_pagination() uses the private function _navigation_markup() to display the screen reader text and the appropriate text. If you look at any of these above functions, there is just no way to remove this screen reader text, not even by just passing an empty string to the screen_reader_text argument because of the following line in _navigation_markup()

2359 if ( empty( $screen_reader_text ) ) {
2360 $screen_reader_text = __( 'Posts navigation' );
2361 }


Beside the fact of the above, there are also no filters provided by any of these functions to alter the output

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme