
Boost your website traffic with one simple piece of code
Ever wanted to boost your site traffic with not that much effort?
Well, after reading The 7 Harsh Realities of SEO I came up with an idea: a very fast way to implement this in Drupal: "All I did was make the post title the title tag and the first sentence of each blog post the meta description."
As I was reading this article, I thought: "This shouldn't be that hard in Drupal". Without making a module but with a quick fix, here is howto:
Add the following code in your theme's template.php
/** * Override or insert PHPTemplate variables into the templates. */ function YOURTHEME_preprocess_page(&$variables) { //Get taxonomy tags from current node. foreach ($variables['node']->taxonomy as $tid => $tag){ $tags .= ', ' .$tag->name; //Strip body text; strip tags & and set max length $varText = check_plain(strip_tags($variables['node']->body)); $description = check_plain(substr($varText, 0, 154)); $tagshead = check_plain($tags); //Fill the $head variable //Edit 'Lucius' to own company or something $variables['head'] = drupal_set_html_head( '<meta name="keywords" content="Lucius, '. $tagshead.'" /> <meta name="description" content="'.$description.'" /> <meta name="title" content="'.drupal_get_title().'" /> ); } }
This code will:
- Add your tags to keywords meta-tag
- Add your page title to title meta-tag
- Add first 154 characters of your body-text to description meta-tag
NOTE
This is a very quick fix, it doesn't work with for example the module nodewords. To do it clean, you have to produce a module and test around with other Drupal seo modules.
Maybe, if we have some time left here at Lucius HQ, we'll provide a module. Hit me on Twitter if you'd like that! And maybe there allready is a module that provides this light weighted, nodewords partly allready does the trick. Please let me know on Twitter. Comments should also be here soon :-)
Related links
Optimize a Single Post On Your Blog for SEO
Kristen.org -- Drupal seo module list