Use the_posts_pagination (); Untitled

When using the_posts_pagination ( see codex ), the page displays the title "post navigation".

Can I 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>',
) );

      

+3


source to share


3 answers


There is a 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 single quotes.

+8


source


I know this is an old post, but for people wanting a simple solution, a simple CSS block would do the trick. No need to configure php.

h2.screen-reader-text {
    display: none;
}

      



or

.post-navigation h2.screen-reader-text {
    display: none;
}

      

+1


source


While looking for a solution, I found this link to be the most relative but not complete solution for my situation. The above answer will raise a warning when validating HTML with W3C.

I found a way to completely remove the title by adding an action that will remove the h2 tag using preg_replace (). Regex is not my best work, so if you have any suggestions please let me now.

I have applied the following in my .php functions:

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');

      

The above function will also remove the "role" attribute from the nav element (raise a W3C warning).

0


source







All Articles