Meta keywords and descriptions in Drupal

By David Pratt / Tags: , / 1 Comment / Published: 21-08-09

Meta tags, once a powerful force in determining the search engine ranking of a page, have seen their influence wane over time to the point that they don’t really count that much at all anymore. However, they are still worth investing some time in so that a when a page is returned in organic search results, the best possible description of the page is presented to the user to encourage them to click through. Best get your online marketers to write them for you then…

In Drupal, the two most popular ways of controlling your meta keywords and descriptions are using the modules:

Both are very good and offer a range of options that allow meta keywords and descriptions to be automatically set for a node of a given content type, but occasionally you’ll find that they just don’t give you the level of control that you require.

Step forward the Drupal “drupal_set_html_head” function – this allows you to add any code you like to the document <head>.

This is the function that I use to set the meta and title tags from within a page/template in Drupal:

function setTitleAndMeta($title = null, $metaK = null, $metaD = null){
	drupal_set_title($title);   //Set page title
	$metaDescription = "<meta name=\"description\" content=\"$metaD\" />";
	$metaKeywords = "<meta name=\"keywords\" content=\"$metaK\" />";
	$meta = $metaKeywords . $metaDescription;
	drupal_set_html_head($meta);
}

Pretty simple huh? A typical call might look like:

setTitleAndMeta("motorbikes | daipratt.co.uk", "motorbikes, gsxr, donors", "I really hope that motorcyclist has signed his organ donor card. If he keeps riding like that and he won't need them anymore.");

Category: Tech

Tags: ,

Posted: on August 21st, 2009 at 9:50 am.

Feeds: RSS 2.0

One Response to “Meta keywords and descriptions in Drupal”

Leave a reply