The state of the art of drupal SEO
I've read several articles about drupal SEO practices. The best one i met is
basic drupal seo on site optimization which is not really "basic" as it covers all the crucial aspects of drupal SEO. I add here some notes to that post:
1. the suggestion to "NOT install the Drupal Sitemap Module" sounds actually obsolete as the xmlsitemap project is now mature and ready for drupal 6.
2. the author is using rewrite rules to deal with canonical urls. at the time of writing, search engines didn't yet support the attribute rel="canonical". the meta tags drupal module now addresses that.
3. he doesn't list the brand new module seo checklist
Drupal SEO quickstart
If you don't have time to read SEO best practices or simply don't want to install a bunch of modules to cope with it, there is a simple shortcut I sometimes have used to achieve some simple improvements. Put this code in your theme template.php:
function __truncate($s) {
return htmlentities(drupal_html_to_text(truncate_utf8($s, 256, TRUE, TRUE)));
}
function phptemplate_preprocess_page(&$vars) {
$vars['meta'] = '';
if ($vars['is_front'] && $vars['mission'] != '') {
$description = $vars['mission'];
}
else if (!Empty($vars['node']->teaser)) {
$description = $vars['node']->teaser);
}
else if (!Empty($vars['node']->body)) {
$description = $vars['node']->body;
}
elseif (arg(0) == 'taxonomy' and arg(1) == 'term' and is_numeric(arg(2))) {
$description = db_result(db_query("SELECT description FROM {term_data} WHERE tid = %d", arg(1));
}
if (!Empty($description)) {
$vars['meta'] .= '<meta name="description" content="'. __truncate($description) .'" />'."\n";
}
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";
}
if (isset($_GET['page']) || isset($_GET['sort'])) {
$vars['meta'] .= '<meta name="robots" content="noindex, follow" />'. "\n";
}
if ($vars['node']->title) {
drupal_set_title($node->title .' | '. $vars['site_name']);
}
}
This is mostly inspired by the blueprint drupal theme template.php with a couple of twists. What it does is self explanatory
1. set up page title with node title if any
2. set up meta description with the node description or term description if any
3. if there are related tags then use those ones as meta keywords
4. add "noindex" if the page comes from a pager link to avoid indexing of duplicate content
After that just put
<?php print $meta; ?>
in the head section of your page.tpl.php.
--
1 comment:
hello and thanks for the tip, but the code to add in template.pho doesn't work..gives parse errors everytime..
Post a Comment