Better pagination SEO with WordPress

Though SEO doesn’t get me all hot and bothered like it does some people, it is on my radar, as I think it should be for all web designers and developers.

One of the blogs I’ve recently subscribed to is SEOMoz, which I like both because it seems to be run by real professionals and thus avoids a lot of the sketchier, black/gray hattish SEO techniques, and also because it seems to have fairly good user comment discussions.

I was particularly interested by a recent “Whiteboard Friday” post in which SEOMoz CEO and co-founder Rand Fishkin discusses an SEO issue with pagination that had arisen with a client. While the blog post title, “A Farewell to Pagination” may be going a bit overboard, there were some definite good points, which basically revolved around the notion that extended pagination in which a website may have hundreds of pages going back years that are all organized in reverse chronological (or some other order) and accessed via pagination can be bad not just for navigation, but also for SEO.

Diving deeper and deeper into the site this way successively dilutes your link juice for the search engines that are crawling your site, potentially leading them to abandon including the deeper/older pages in their index, leading to their exclusion from search results. Fishkin discusses some navigation workarounds that are improvements both from an SEO and user experience point of view.

Applying this to WordPress, I wondered if there was a WordPress filter hook that would allow you to create a simple plugin that could appropriately add the rel="nofollow" attribute to your pagination anchor tags, so that pagination is still available to the user but won’t have the deleterious SEO effects. Turns out there isn’t, but there’s another easy, though less elegant, way to accomplish this, which is by defining a function in your WordPress templates’ functions.php file.

Just copy and paste the previous_posts_link and next_posts_link functions from wp-includes/link-template.php into your functions.php file, and make the following simple modification

function nofollow_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="nofollow" href="';
		next_posts($max_page);
		echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
	}
}

function nofollow_previous_posts_link($label='« Previous Page') {
	global $paged;
	if ( (!is_single())	&& ($paged > 1) ) {
		echo '<a rel="nofollow" href="';
		previous_posts();
		echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
	}
}

With that done, simply use the new functions wherever in your template you want the nofollow functionality (e.g. in index.php). This is really only the beginning of a solution to this issue, as you’ll have to rework other aspects of your navigation if you really want to add rel="nofollow" to all your WordPress pagination.

12 thoughts on “Better pagination SEO with WordPress”

  1. WordPress is a great blogging platform and getting it search engine optimized really isn’t a hard task. Using proper permalinks and robots.txt file to prevent duplicate content and a few other methods can really make a difference. The All in One SEO plugin is really the best bet.

  2. Thanks, I’ll check it out.
    Right now this bog is not really at all optimized for SEO. I’m using a Dublin Core plugin and no meta keywords or description… should probably take care of that soon!

  3. Hey,
    Interesting post, i like the way you write. Just bookmarked your blog and i”ll make sure to visit it at lease once a week.
    Also, free free to email me if you have “some” exclusive information on this topic. I don’t mind paying for gold 🙂

  4. Hello would you mind stating which blog platform you’re using? I’m going to start my own blog in the near future but I’m having a tough time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something completely unique. P.S Sorry for being off-topic but I had to ask!

  5. on to this issue, as you’ll have to rework other aspects of your navigation if you really want to add rel=”nofollow” to all your WordPress pagination.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.