Advanced Page Title Tags Using Drupal Views

View of some hills and valley

In Part 1 of Page Title Tags in Drupal we looked at setting your front page and individual page <title> tags. But reviewing our Google Webmaster Tools report on HTML Improvements, we saw that it reported five Duplicate Title Tags.

Duplicate title tags

These are all Blog archive pages, generated by Views to show teasers of all our blog posts published in a single month. They are all just using the default - <title>FireRoad Blog | FireRoad Digital</title>. So we need to enable a Metatag sub-module to let us set <title> tags for pages created by Views. Look under SEO in admin/modules and enable Metatag: Views.

Drupal metatag module enable Views

This will add a new option inside all of your Views to set Meta Tags. Edit one of your Views and you should see this in the middle section of the initial admin edit screen:

Drupal Metatag settings link inside of a Views edit screen

Out of box it is set to use defaults, which if we click through shows us:

Drupal Metatag module Views defaults

So, similar to the default for individual nodes, but using the [view:title] token rather than the [node:title] token. So what is the [view:title] token set to? Click on the appropriate View Display and look under Title. For our main /blog page, it is set to ..

Drupal View page title


If we look at the source for the /blog page, the title tag is then appropriately set to <title>FireRoad Blog | FireRoad Digital</title>, following the rule set under the Metatag config we saw above. And that's fine for that page. But we need to differentiate each of the archive pages. Each situtation will be different - you may need to find a token that you can use that is specific to that page, like the date or a username. We are using a contextual filter to restrict the view to just show blog posts for that month and setting the title using the name of that month an the year, so we get a unique <title> tag for each month. Such as <title>FireRoad Blog: December 2014 | FireRoad Digital</title>. Just figure out a token or such that will make each page title unique. And no more duplicate page titles ... and complaints from Google Webmaster Tools! You can see all the available tokens if you click on the Open Graph option on the View's Metatag configuration and click on Browse available tokens (not sure why it got put there...)

Don't forgot to do the same for the Description meta tag. We'll cover that in a future post.