How can I remove the h2 tag used in the screen reader text? I use the following $args, but h2 is still in it:

the_comments_pagination( array(
    'add_fragment' => '',
    'screen_reader_text' => __( '<h3>Test</h3>' )
) );
  • Can you add some context or explanation for why you need to do this? The screen_reader_text parameter is only for the text inside, not the full HTML markup – Tom J Nowell Oct 31 '16 at 14:54

There's a couple issues.

1) You're not supposed to put HTML inside most translations strings ( such as this ).

2) The screen_reader_text argument does not accept HTML at all, you need to filter the HTML by using the following hook:

navigation_markup_template - Filters the navigation markup template.

 * Modify the given HTML
 * @param String $template  - Comment Pagination Template HTML
 * @param String $class     - Passed HTML Class Attribute
 * @return String $template - Return Modified HTML
function change_reader_heading( $template, $class ) {

    if( ! empty( $class ) && false !== strpos( $class, 'comments-pagination' ) ) {
        $template = str_replace( '<h2', '<h3', $template );

    return $template;
add_filter( 'navigation_markup_template', 'change_reader_heading', 10, 2 );

The above searches the $template HTML string and replaces all h2 tags with h3 tags.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.