Drupal 7 Add nofollow to Views Pager Links

  • Published by steve on 18 April 2016.

SEO Reason for using nofollow on Pager Links

This is a core hack for Drupal 7 to add rel="nofollow" to your numbered pager links.
Previously I was using rel next and rel prev as well as canonicals to the first page, however, I found that Google consistently indexed various pages for certain queries even when there were more relevant pages it could show. The second reason for this is that Google would use the pager numbers as my page titles in SERPS (even in sitelinks). My prediction is that by preventing link juice from passing through the pager links, my other sub-category pages and the first page of the main categories should bubble up in the search results.

The Solution

Currently, the problem is that this will only add rel="nofollow" to your "next" button and higher page numbers. So far I have not found a way to add this to all pagers (I will update this post as soon as I can track the solution down)

Edit your pager.inc under the /includes directory (be sure to make a backup first).
Find: 'parameters' => $parameters)
Replace with: 'parameters' => $parameters,'attributes'=>array('rel'=>'nofollow'))

The Objection: "You can't hack Drupal Core!!!"

I have tried various modifications to template.php without success, if you have a simple solution without hacking core let me know in the comments below. If it works I will repent and update this post to your far superior method.