Skip to main content

Drupal SEO - Nofollow Links

I have been updating this site recently and ran into a few issues with Google indexing tag taxonomy pages and following tag links which had less than desirable results for my SEO efforts. In general, taxonomy pages such as tag archives should have a noindex meta tag as these types of pages often contain duplicate content.

To further fix the issue, I created a simple theme function that adds the rel=nofollow attribute to the links within the tag taxonomy. This means that Google shouldn't follow links to tag archives which in turn should provide a nice boost to other links on my site.

/**
 * Add nofollow attribute to any link within the taxonomy vocabulary_1
 */
function yourtheme_preprocess_link(&$vars) {
    if ($vars['options']['entity']->vocabulary_machine_name == 'vocabulary_1') {
	 	$vars['options']['attributes']['rel'] = 'nofollow';
    }
}

 

Looking for Expert WordPress or Drupal development?

I am a freelance website developer and designer based in the UK. I work as a remote Drupal developer, WordPress developer and Front-end developer for a variety of startups, charities and international businesses in Bristol, Bath, London and Europe. You can learn more about me by visiting my resume page.

Get in touch for a free quote on your next project and if you want to connect me with then check out my LinkedIn profile.