Adding rel=”next” & rel=”prev” for paginated archives

Try putting this snippet in your functions.php

<?php
function rel_next_prev(){
    global $paged;

    if ( get_previous_posts_link() ) { ?>
        <link rel="prev" href="https://wordpress.stackexchange.com/questions/36800/<?php echo get_pagenum_link( $paged - 1 ); ?>" /><?php
    }

    if ( get_next_posts_link() ) { ?>
        <link rel="next" href="<?php echo get_pagenum_link( $paged +1 ); ?>" /><?php
    }

}
add_action( 'wp_head', 'rel_next_prev' );
?>

And if you don’t want the next and prev rel links to show up on the singular pages just wrap the output markup in a !is_singular() if condition

Leave a Comment