- Home
- Blogs
- George Boobyer's blog
- Drupal Blueprint theme playing SEO nicely with other modules
Drupal Blueprint theme playing SEO nicely with other modules
Getting your page title and metatags correct is great for SEO and enables your readers to locate your content by getting it indexed well.
In this post we'll see how to get your modules and theme to play nicley together to ensure that your page structure is optimal for web standards and indexing. In most cases this can be sorted with a simple fix.
Drupal and its excellent contributed modules and themes provide a wealth of solutions to give you all the control you'll need. Drupal has an excellent developer network and one of its key features and richness is that functionality is rarely duplicated across modules. People collaborate to concentrate their collective efforts on fit for purpose modules as opposed to creating many modules with overlapping functionality. This makes it very straight forward when choosing a module for a specific task - as opposed to having to evaluate many similar 'plug ins'. The only exception is where ficntionality os provided by themes that may wrestle with modules to achieve a specific function.
Many Drupal themes have in built functionality to sort out titles, metatags and the like and this can be great as a starter. However, in general you will be better off using a dedicated module to give you the control you need over such things. Modules such as Page Title, NodeWords and other SEO friendly modules give you more complete control than the defaults chosen by a theme developer.
We are great fans of Blueprint (the theme that gives you the blueprint framework) - it is a great start for new themes.
One of the things Blueprint as a theme does is set up some great defaults for titles and metatags - but what if you want to override these?
In the template.php of the blueprint theme you can see:
if (!module_exists('page_title')) {
// Fixup the $head_title and $title vars to display better.
$title = drupal_get_title();
$headers = drupal_set_header();
// wrap taxonomy listing pages in quotes and prefix with topic
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
$title = t('Topic') .' “'. $title .'”';
}
// if this is a 403 and they aren't logged in, tell them they need to log in
else if (strpos($headers, 'HTTP/1.1 403 Forbidden') && !$user->uid) {
$title = t('Please login to continue');
}
$vars['title'] = $title;
if (!drupal_is_front_page()) {
$vars['head_title'] = $title .' | '. $vars['site_name'];
if ($vars['site_slogan'] != '') {
$vars['head_title'] .= ' – '. $vars['site_slogan'];
}
}
}
This basically says, if you don't have the page title module, then blueprint will create some great defauklt tiles out of your site name, slogan and taxonomy for you. If you do have Page Title (and you should have it as a module on all your sites!) then let it handle the title tag.
Then Blueprint addresses the metatags - It is good SEO to have keyword rich titles and metatags.
$vars['meta'] = '';
// SEO optimization, add in the node's teaser, or if on the homepage, the mission statement
// as a description of the page that appears in search engines
if ($vars['is_front'] && $vars['mission'] != '') {
$vars['meta'] .= '<meta name="description" content="'. blueprint_trim_text($vars['mission']) .'" />'."\n";
}
else if (isset($vars['node']->teaser) && $vars['node']->teaser != '') {
$vars['meta'] .= '<meta name="description" content="'. blueprint_trim_text($vars['node']->teaser) .'" />'."\n";
}
else if (isset($vars['node']->body) && $vars['node']->body != '') {
$vars['meta'] .= '<meta name="description" content="'. blueprint_trim_text($vars['node']->body) .'" />'."\n";
}
// SEO optimization, if the node has tags, use these as keywords for the page
if (isset($vars['node']->taxonomy)) {
$keywords = array();
foreach ($vars['node']->taxonomy as $term) {
$keywords[] = $term->name;
}
$vars['meta'] .= '<meta name="keywords" content="'. implode(',', $keywords) .'" />'."\n";
These vars (meta and head_title) are then printed in the theme template.
But is you are using the nodewords module (and again a great standard to have in your site build) the you will get doubling up of your keywords and description metatags. Not good for SEO
So rather than hack the contributed theme - you can use the same method as used for page titles and undo the blueprint metattagging.
In your template.php for your custom theme (and create one if you don't have one, put:
function [yourcustomthemename]_preprocess_page(&$vars) {
if (module_exists('nodewords')) {
unset($vars['meta']);
}
}
This simply undoes the work that blueprint did and removes the duplicates.
Make sure that you set up the defaults in nodewords though otherwise you'll get none.
I have contacted the maintainer to hopefully get the 'fix' for nodewords incorporated along with the one for page titles.
This technique can work in many other cases and it is always worth having a look at your page source to see what results form your theme and modules outputs and in cases such as this simply check on the source logic so you can see how to sort it out.
And... as ever is you find another such example pass it on..
Contact Details
Blue-Bag Ltd
- info [at] blue-bag.com
- Telephone: 0843 2894522
- Blue-Bag HQ:
The Garage, Manor Farm
Chilcompton, Radstock
Somerset, BA3 4HP, United Kingdom - Telephone: (+44) 01761 411542
- Blue-Bag Brighton:
Unit 35 Level 6 North, New England House
New England Street, Brighton
BN1 4GH United Kingdom - Telephone: (+44) 07944 938204
- VAT GB 748125034
- UK Company Reg: 3932829