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="';
		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="';
		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.

The semantic web gets friendly

I’ve had a passing interest in the semantic web since I first heard the term a few years ago, but hadn’t explored it much beyond using the hCard microformat for contact info on a few websites I’ve done. It sounded like an interesting idea, but in the absence of significant, working applications beyond the academic world, it didn’t really capture my attention. Not to mention that there were (and are) some very vocal opponents of the idea, with a wide-ranging set of criticisms (some well-taken, some just strange).

But it recently popped back into mind when I chanced across a post entitled Semantic web comes to life from Joel Alleyne’s blog, Knowledge Rocks. Given that I still have access to the e-journal database of one of my former Universities, I logged in a grabbed the full Scientific American article Joel had linked to, The Semantic Web in Action. The article spills a good deal of ink highlighting various real-world applications of semantic web (or at least semantic web-ish) technologies, mostly from the medical field, where practical applications abound. (The stories shared by the article authors reminded me of a story I read a while ago about a researcher without any actual health training who made a significant cancer treatment-related discover just by linking together existing research that hadn’t yet been put together — I wish I could remember whether it was on the web, in Harper’s, or possibly a CBC Ideas episode).

So I’m on a bit of a semantic web kick now… I’ve FOAF-a-matic‘ed myself, and am reading all I can. It’s a fairly timely rediscovery as my workplace (Canadian Education Association) moves towards implementing a new website. We’re sitting on a goldmine of content (particularly from our magazine, Education Canada) that really needs indexing and some good metadata, and it will be interesting to see if RDF or something like it can fit into the emerging picture.