Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough
Mar 27 2009
Mar 27

One of Google's current experiments enables participants to use options for restricting search results by certain criteria or to use tools like the wonder wheel for related query suggestions on Google's search result pages.

In this screencast you can see how some of these new search tools, e. g. the timeline and image view, look like and what Google's wonder wheel suggests when searching for Drupal.

[embedded content]

If you want to try this yourself and are not based in the US or for some reason don't want to participate in the experiment, paste the following JavaScript code in the address bar of your browser when on google.com and hit return to set the cookie, as demonstrated in the video. Have fun!

javascript:void(document.cookie="PREF=ID=4a609673baf685b5:TB=2:LD=en:CR=2:TM=1227543998:LM=1233568652:DV=AA:GM=1:IG=3:S=yFGqYec2D7L0wgxW;path=/; domain=.google.com");

Via Google Blogoscoped

Jan 30 2009
Jan 30

When developing Drupal modules or checking out modules I don't know yet, I run an instance of Drupal on my local machine. Sooner or later I feel the need to erase this installation and do a fresh install. The Drupal installation process is pretty straightforward and simple making it a good candidate for automating at least parts of it.

In the Drubuntu Drupal group I found this install script for Drupal that does not only install Drupal but also creates an operating system user, as well as apache2 and DNS configurations. A pretty useful script, but it does too much for my development needs.

[embedded content]

I took it as a basis to create a simpler version that merely installs Drupal. In the screencast I demonstrate using this bash script that you can download here (REMEMBER TO ALWAYS DO BACKUPS!!!) from Drupal's CVS repository.

To use it you may need to modify the server root path or set a password for the MySQL root user. Obviously you need a Bash interpreter and wget for downloading. Have fun installing Drupal even more quickly!

Jan 08 2009
Jan 08

The logo of a Web site is not only important for branding but also as a navigational element, that many users expect to link to the home page. According to usability guru Jakob Nielsen the first of Ten Good Deeds in Web Design you can do is link your logo to the home page except you are on the home page.

Mr. Nielsen conducted many usability studies and has written groundbreaking articles and books on Web usability. Good reason for me to trust him when it comes to this topic, especially when it sounds completely plausible.

Why Linking with JavaScript?

There are many parallels between creating a usable and creating a search engine friendly Web site, but often enough you need to take subtleties into account. According to Rand Fishkin — let me call him the Jakob Nielsen of SEO — only the first anchor text counts for Google and he is not the only SEO expert who observed this.

On Linux-Netbook.com, a Drupal site I created a few months ago, the site logo did not link to the home page in favor of the site name, which appears later in the HTML source. I have no evidence and not tested whether anchor text is more important than ALT text, but that was my reasoning.

To fix this usability crime without sacrificing my SEO efforts, I added the following 5 lines of jQuery code to the theme's script.js file:

  if (document.location.pathname != Drupal.settings.basePath) {
    jQuery('#logo').wrap('<a href="http://www.seo-expert-blog.com/blog/linking-the-logo-to-the-home-page-with-javascript/' + Drupal.settings.basePath + '"></a>');

This code links the image with the ID logo to the home page unless we are on the home page, provided the user agent interprets JavaScript.

I assume that Google's engineers are smart enough to make Googlebot understand this JavaScript snippet, but I guess it does not play a role in the which link comes first game. In case it does, the ALT text contains the site name as well.

Oct 07 2008
Oct 07

One of the great improvements in Views 2 is the ability to create various page and block displays for one view. Block views can be linked to a page display when the More link option in the block's settings is enabled.

If there are one or more page displays set up in the view, the page to be linked can be chosen after clicking on the link next to the Page display option. See the screenshot below for an example:

Views 2 Block settings: Link display optionViews 2 Block settings: Link display option

The default anchor text of more links in block views is more which comes with the benefit to be pretty generic but is not good from an SEO point of view.

Anchor texts are very important for search engine rankings as the number one search result for click here demonstrates. Neither the words click nor here actually occur on the Adobe Reader download page, but it is linked with this anchor text very often.

To replace the default anchor text for more links with the title of the linked page, which is hopefully more meaningful, you can override the views-more.tpl.php template file by taking the following steps:

  1. Copy views-more.tpl.php from PATH_TO_VIEWS_MODULE/theme/ to your theme directory
  2. Replace the content of views-more.tpl.php in your theme directory with the code below.
  3. Clear the theme cache. You can achieve this by clicking on Clear cached data at the bottom of the Performance settings form on the admin/settings/performance page. This will clear all cached data, which should be avoided on high traffic sites. Alternatively you can call drupal_rebuild_theme_registry() in your template.php file once after you copied and edited the views-more.tpl.php file or by executing this SQL query
    DELETE FROM `cache` WHERE cid LIKE 'theme_registry%';

Code in views-more.tpl.php

= strlen(base_path());
$path = substr($more_url, $offset);
$menu_item = menu_get_item( $path );
$title = check_plain($menu_item['title']);

<div class="more-link">
  <a href="http://www.seo-expert-blog.com/tutorial/how-to-optimize-views-2-more-links-anchor-texts/<?php print $more_url; ?>">
    <?php print $title; ?>

The $more_url variable is made available by the views module in the views-more.tpl.php template file. It contains the absolute path to the linked page view. To get the title of the linked page, the internal Drupal path is extracted from $more_url using PHP's substr() function.

The internal Drupal path is needed to call menu_get_item(), which returns a menu router item that in turn contains the page title in the value for the title array key.

Actually, I am not sure whether calling check_plain() on the title is necessary here, since I assume that this taken care of before the router item is written to the database. Any insight on that is greatly appreciated.

The remainder of the code in the template file consists of the mark up of the more link with the linked page title as the anchor text.

That's it. A simple yet effective method of optimizing the anchor texts of more links in Views 2 blocks. A demonstration of this code in use can be seen in various blocks on linux-netbook.com.

The screenshot of the views settings page and the annotations are done with the awesome Firefox extension FireShot, that I just discoverd today. There is great software outside the Drupal universe ;-)

Sep 08 2008
Sep 08

According to Dries' State of Drupal 2008 presentation backed by a survey with 1367 participants the drupal.org redesign is a very important task for improving the user experience of the Drupal project as a whole.

In the current stage of the redesign process feedback from drupal.org users is essential. To participate the GDO Redesign group is a good starting point.

And that's not the only place. Leisa Reichelt who works with Mark Boulton Design on the redesign project recently opened the floodgates and created groups on flickr, slideshare and twitter to share resources and discuss with Drupal users.

To better keep track I created a Yahoo Pipe that aggregates these sources and a Widgetbox widget that can be embedded on websites or personalized start pages.

Yahoo Pipe Badge

Widgetbox Widget

Aug 13 2008
Aug 13

Google Webmaster Tools includes a tool called content analysis that you find in the Diagnostics section. The content analysis tool reported a suboptimal number of duplicate title tags and meta descriptions for some Drupal sites that I monitor with these tools.

Getting rid of duplicate title tags and meta descriptions caused by the pager is actually quite simple. When using the Meta Tags module with the setting ALL=INDEX,FOLLOW for Default robots meta tag: you can adjust the robots Meta tag in your theme, so that pages that contain the page parameter in the URL are not indexed using the following code snippet in the head section of your page.tpl.php template file.

if (isset($_GET['page'])) {
$head = str_replace('<meta name="robots" content="index,follow" />',
'<meta name="robots" content="noindex,follow" />', $head);

If you do not use the Meta tags module or another solution to add Meta tags to the head section of your HTML, the robots Meta tag is not contained in your page source. In this case you can simply append this tag to your head variable like that.

if (isset($_GET['page'])) {
$head .= '<meta name="robots" content="noindex,follow" />';

Setting the robots Meta tag to noindex,follow tells search engine crawlers that care about the robots Meta tag and the robots exclusion standard to not index these pages, i.e. they won't appear in search engine results but linked pages will be crawled, provided they are not linked with rel="nofollow".

Adding this code to your theme is a quick hack and not the optimal solution, because it is not easily reusable. Since I want to get rid of this in my theme sometime in the future, I added a feature request to the Meta tags module with a patch that resolves issues with duplicate title tags and meta descriptions on pages generated by Drupal's pager.

The fact that Google displays such issues in the diagnostics section of their webmaster tools indicates that they play a role in evaluating the quality of your site. It is not likely that your site will be considered spam and get banned because of these issues, but it is certainly better to get rid of them.

May 28 2008
May 28

Today LinuxTag 2008 started in Berlin, Germany. LinuxTag is Europe's leading exhibition on Linux and Open Source software and will go on until Saturday (May 31, 2008) at Berlin's Messezentrum unter dem Funkturm.

There is a Drupal booth (no. 217) located in Halle 7.2a organized by the Drupal User Group Berlin. And it looks like that:

Drupal Stand Linuxtag 2008

We introduced quite a few people to Drupal who said they will give it a try and also got some nice feedback from LinuxTag's organization staff, not only because of the cool Drupal shirts we were wearing.

You can find more information on Drupal at LinuxTag Berlin 2008 in German on the group's website and on the new be Drupal website set up to promote Drupal related events and activity in and around Berlin.

If you are an Open Source enthusiast and happen to be in Berlin, don't let the chance pass by to visit this event where many people volunteer to promote such diverse projects as Drupal, MPlayer, Horde, Asterisk, Zope — who where so kind to give away some free beer and Brezeln to celebrate their 10th anniversary today — and many more, not to forget the many flavors of Linux.

May 02 2008
May 02

After upgrading to Drupal 6 I opted for a quick and dirty XML sitemap approach. Before I was using the XML Sitemap module which is currently available for Drupal 6 as a development snapshot or directly from CVS. The module offers settings for priority and change frequency. Moreover the module allows for adding taxonomy term and user URLs to the sitemap.

I only wanted nodes and the front page to appear in the sitemap's XML output without priority or change frequency information. Having the path and pathauto modules enabled, which ensure that every node gets a meaningful and search engine friendly URL, a simple database query joining two tables is enough to get the necessary data for all published nodes.

Code Snippets

To make the sitemap reachable via a URL a menu item of the type MENU_CALLBACK goes into the menu hook of a module named custom. The menu hook changed in Drupal 6 and so did the whole menu system which was completely rewritten by chx. To learn more about it, read the menu module documentation.

function custom_menu() {
$items = array();
$items['sitemap'] = array(
'title' => 'XML Sitemap',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'page callback' => 'custom_sitemap'

When the URL /sitemap is requested the function custom_sitemap() is called. The sql query joins the node and url_alias tables to retrieve all modified dates and URL aliases of published nodes which are stored in an associative array called urls. The URL aliases 403 and 404, that are used for custom error pages, are omitted from the array.

What follows is putting together the XML output string in a here document and a foreach loop and printing it out.

function custom_sitemap() {
$base = ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . base_path();
$urls = array();
$result = db_query("SELECT ua.dst, n.changed FROM {node} n INNER JOIN {url_alias} ua ON ua.src = CONCAT( 'node/', n.nid ) WHERE n.status =1 ORDER BY n.changed DESC");
$r = db_fetch_object($result)) {
    if (
$r->dst != 404 && $r->dst != 403) {
$urls[$base . $r->dst] = $r->changed;
header('Content-Type: text/xml');
$xml =<<<EOF
<?xml version="1.0" encoding="UTF-8"?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  foreach ($urls as $url => $t) {
    $xml .= '<url>';
    $xml .= '<loc>' . $url . '</loc>';
    $xml .= '<lastmod>' . date("Y-m-d", $t) . '</lastmod>';
    $xml .=  '</url>';
  $xml .= '</urlset>';
  print $xml;exit();

Apr 09 2008
Apr 09

This site is now running on Drupal 6, yeah! The basic part of the upgrade process was straightforward:

  • Backing up the site with a backup script.
  • Deactivating all contrib modules and themes.
  • Moving the Drupal 5 files to a new directory.
  • Unpacking Drupal 6 and contrib modules in the web root directory.
  • Running the database update script.
  • Activating contrib modules and themes.
  • Running the database update script again.

If you plan to upgrade a Drupal site without having done so before, I highly recommend this screencast by Angie Byron. The video walks you through upgrading a site from Drupal 4.7 to Drupal 5, but most of the information applies to a Drupal 5 to 6 upgrade as well. Also read the Upgrading Handbook.

The most involving part of this particular upgrade was getting the theme and a custom module to work with Drupal 6. Fortunately there is a fantastic theming handbook for Drupal 6, articles about converting 5.x themes to 6.x and converting 5.x modules to 6.x and the very helpful coder module.

The coder module generates a report for the selected modules and themes, telling which parts of your source code need to be changed to work with Drupal 6. Though it missed some occurrences of the url() and l() functions, that changed in Drupal 6, and the deprecated _phptemplate_variables() function, that is replaced by preprocess functions, the coder module was a great help.

Below is a screenshot of the coder module report. For each warning or error the line number of the file, a description of the problem linking to relevant documentation and the problematic piece of code are displayed.

Code Review Screenshot

Thanks to the available documentation, tutorials and tools the upgrade to Drupal 6 was quick and painless.

Feb 18 2008
Feb 18

In this short video Search Engine Marketer Brian Chappell recommends some basic SEO measures for a Drupal site. Since Drupal is very search engine friendly out of the box, there are not many things you need to do.

Brian recommends to activate the core path module and to additionally install the Page Title, Global Redirect, and Meta Tags modules. In his accompanying blog post are also some notes on the .htaccess and robots.txt files.

I haven't used the Page Title module yet, but agree that Path, Global Redirect, and Meta Tags (nodewords) should be installed and activated, and also the XML Sitemap module.

Last year I wrote about SEO modules for Drupal and other CMS with some more modules that are worth taking a look at. There is also the SEO Checklist module by Ben Finklea to help you make your Drupal site even more search engine friendly.

One hint from me. Make your site friendly for yourself and your users first. Then take care of the bots, if you feel like doing so.


I lost some comments on this post, that were mistakenly classified as spam by the spam protection I am using. Greg Knaddison, a.k.a. greggles, pointed to his free Drupal SEO video-course, where he covers the most important Drupal core settings and contributed modules for optimizing your site. Check it out!

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web