WordPress

WordPress rel=”prev” and rel=”next”

Quite a few years ago, folks would fine-tune their pages using a technique called nofollow. Basically, if you wrote rel=”nofollow” within an anchor tag (a link), the theory was that the search engine would ignore that link and ignore the next page. It’s been used extensively by sites like Wikis and within comments so that user-edited links wouldn’t be abused and followed.

Search Engine consultants quickly realized how useful these types of links were, sprinkling them throughout links on the page so that some links were weighted more heavily than others. The practice was called page-sculpting and was eventually looked down upon by Google.

I still utilized nofollow on my pagination links (those are the next and previous links) on the site. That way my pages (2, 3, 4, etc.) wouldn’t be included in search results. I did this by a modification I found on Katz Web Services page.

Last week, Google provided an update where pagination links could be coded with rel=”next” and rel=”prev” within the anchor tags. Thankfully, the functions (which should be added to your theme’s functions.php file) are quite easy to edit. Here they are with the update.

Customization for Next Page links:


function mtb_next_posts_link($label='Next Page', $max_page=0) {
global $paged, $wp_query;
if ( !$max_page ) {
$max_page = $wp_query->max_num_pages;
}
if ( !$paged )
$paged = 1;
$nextpage = intval($paged) + 1;
if ( (! is_single()) && (empty($paged) || $nextpage >= $max_page) ) {
echo '>a rel="next" href="';
next_posts($max_page);
echo '" title="Next page – Go to page '.$nextpage.'">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'>/a>';
}
}

Customization for Previous Page links:


function mtb_previous_posts_link($label='Previous Page') {
global $paged;
if ( (!is_single()) && ($paged > 1) ) {
$prevpage = intval($paged) – 1;
echo '>a rel="prev" href="';
previous_posts();
echo '" title="Previous page – Go to page '.$prevpage.'">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'>/a>';
}
}

Add those functions to functions.php and then use the function in your index.php and other pages where pagination links are utilized. That’s all it takes to implement this new feature on your WordPress site or blog – something I’d highly recommend! Hopefully, the developers of WordPress will implement this change within the core application. To date, they haven’t paid much attention to search engine optimization, though, so I’m not holding my breath.

2 Comments

  1. 1
  2. 2

    Thanks for the great post. Unfortunately, I don’t understand how to actually implement this… So I’m going to now pray (and do a little Google-searching) that there is a plug-in that does this for me…

Leave a Reply