use the_posts_pagination(); without title
Solution 1
There is "screen_reader_text" property that should help you
the_posts_pagination( array(
'screen_reader_text' => ' ',
'prev_text' => __( 'Previous', 'twentyfifteen' ),
'next_text' => __( 'Next', 'twentyfifteen' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( '', 'nieuwedruk' ) . ' </span>',
) );
Note: Hence the space between the single quotes.
Solution 2
While searching for a solution i've found this link to be the most relative but not a complete solution for my situation. Above answer will cause a warning when validating your HTML with W3C.
I've found a way to completely remove the heading by adding an action which will remove the h2 tag with preg_replace(). Regex isn't my best job so if you have suggestions please let me now.
I've put the following action in my functions.php:
function sanitize_pagination($content) {
// Remove role attribute
$content = str_replace('role="navigation"', '', $content);
// Remove h2 tag
$content = preg_replace('#<h2.*?>(.*?)<\/h2>#si', '', $content);
return $content;
}
add_action('navigation_markup_template', 'sanitize_pagination');
Above function will also remove the "role" attribute from the nav element (Causes W3C warning).
Solution 3
I know this is an old post, but for people wanting simple solution, a simple CSS block would do the trick. No need to tweak php.
h2.screen-reader-text {
display: none;
}
or
.post-navigation h2.screen-reader-text {
display: none;
}
Remi
Updated on July 07, 2022Comments
-
Remi almost 2 years
When using the_posts_pagination (see codex) the pagination displays a title "post navigation".
Is it possible to turn this off?
For example using something like:
the_posts_pagination( array( 'title' => '', // this should hide the title 'prev_text' => __( 'Previous', 'twentyfifteen' ), 'next_text' => __( 'Next', 'twentyfifteen' ), 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( '', 'nieuwedruk' ) . ' </span>', ) );
-
Remi about 9 yearsHi @asgu, thanks for the reply. However that doesn't seem to change it though.
-
Remi about 9 yearsAdding a space between the single quotes seems to do the trick.
-
aletede91 almost 6 yearsWhat about SEO? H2 is still in page
-
Fusion almost 2 yearsThis does not solve the problem. It is still generating undesired HTML rubbish, which may not visible to users, but it is visible for search engines, bots, etc.