5

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.

  • you can do this by using query and append it – Niraj Chauhan Dec 18 '11 at 17:40
  • @ntechi, thank you for your quick reply. My guess is however this answers about 99,9% of all questions listed here. I have to admit I was hoping for something a bit more detailed. – user5424 Dec 18 '11 at 17:49
  • your aim is to add a rel in next and previous link? – Niraj Chauhan Dec 18 '11 at 17:52
  • The one Google advises, yes. Not the ones that are currently used by WordPress default. – user5424 Dec 18 '11 at 17:54
  • @CorvanNoorloos The one Google advices is in the head section, not directly at the link element... – kaiser Dec 18 '11 at 19:44
9

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

  • Thanks @Joshua, this works even better than the gist mentioned above! – user5424 Dec 20 '11 at 17:05
  • I would recommend using is_archive() instead of ! is_singular() – Josh Mountain May 8 '14 at 21:43
  • get_next_posts_link() not working without the max_num_pages parameter, how can I get this variable in functions.php? am I missing something ? – HOY Aug 14 '17 at 3:15
  • Does ### if ( get_previous_posts_link() ) ### PHP syntax mean: replace the function get_previous_posts_link() with the function that follows? – Revious Oct 15 '18 at 9:22
0

This pretty much does exactly that, as a plugin - http://wordpress.org/extend/plugins/pagination-rel-links/

-3

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.

  • If I understand correct you're suggesting to let JavaScript handle this? Since Google or any other search engine doesn't understand JavaScript, I doubt this would be the ideal solution. – user5424 Dec 18 '11 at 18:17
  • yaa that would be, better would be you edit that PHP code itself or wait for another answer – Niraj Chauhan Dec 18 '11 at 18:18
  • It always be a good practice to do it server-side.. – amit Jul 17 '12 at 0:30
  • This is pretty useless for SEO – Richard Jan 4 '17 at 18:24

Your Answer

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