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

Does someone perhaps know a plugin or snippet (besides Yoast’s WordPress SEO) to accomplish this perhaps? Pagination with rel=“next” and rel=“prev”

The only thing I’ve come across seems to be an 3-month old Trac ticket.

Related posts

Leave a Reply

3 comments

  1. Try putting this snippet in your functions.php

    <?php
    function rel_next_prev(){
        global $paged;
    
        if ( get_previous_posts_link() ) { ?>
            <link rel="prev" href="<?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

  2. Ok then this will be a good solution:

    $('YOUR_PAGINATION_A_ID').attr('rel', 'next');
    $('YOUR_PAGINATION_A_ID').attr('rel', 'prev');
    

    Try this, it might help you.