1

For the Pagination on the front page ort the Homepage I am using this one →

<?php the_posts_pagination( array( 'mid_size' => 2 ) ); ?>

Codex Reference #1

Codex Reference #2

In the actual Browser, it generated a div like this →

<nav class="navigation pagination" role="navigation">

W3C Validation is throwing this error →

Warning: The navigation role is unnecessary for element nav.

From line 301, column 2; to line 301, column 54 ↩ <nav class="navigation pagination" role="navigation">↩ <h2

Question →

Is there a method to get rid of this →

role="navigation"

1 Answer 1

3

navigation is the default value for role attribute in nav elements. So, if the browser/technology understands HTML5 and is fully standard compliant, then it is unnecessary, but what if not? I don't get the advantage of removing it; it just make sure that any technology reading the document knows what the element is used for.

Anyway, if you want to remove it, you can filter the navigation markup template:

add_filter( 'navigation_markup_template', 'cyb_navigation_template' );
function cyb_navigation_template( $template ) {
    $template = '
    <nav class="navigation %1$s">
        <h2 class="screen-reader-text">%2$s</h2>
        <div class="nav-links">%3$s</div>
    </nav>';

    return $template;

}
3
  • Code had no effect on latest wp twentysixteen theme Commented Dec 13, 2019 at 19:12
  • is there really need to add the $template argument in the function ?
    – cap340
    Commented Aug 20, 2020 at 2:09
  • The only reason I see here to remove the role="navigation" is for W3C validation which has impact in your website pagerank. But I agree with you. Some older browsers may need this to recognize the element. Commented Dec 29, 2020 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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