Remove h2 Tag in screen_reader_text

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' = __( 'h3Test/h3' )
) );

Topic wp-parse-args pagination Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.