Custom Regions

Creating Custom Regions In Drupal 6 Themes

Previously, I covered the topic of creating custom regions in Drupal 5 themes. However, Drupal 6 introduced a new process for creating custom regions in themes and it is still one of the topics people ask about most frequently.

So, here's a tutorial on how to create custom regions in your Drupal 6 themes. In this example I will use the Garland theme, and insert a new region called 'Uber content', which I'll position above everything in the main content area.

Custom Drupal 6 theme region

It's basically a two-step process:

  • step 1 - define the custom region in your theme's .info file
  • step 2 - insert some PHP in your theme's page.tpl.php file wherever you would like the new region to appear

Creating Custom Regions

UPDATE
The following tutorial covers the creation of custom regions in Drupal 5 themes. If you are using Drupal 6 please see the newer creating custom regions in Drupal 6 themes instead.

----------

All Drupal themes you download will come with a number of pre-defined regions into which you can already place blocks (normally header, left-sidebar, content, right-sidebar, footer), but it can sometimes be useful to create your own.

This can seem a little daunting at first, but it's really just a simple two-step process:

  • step 1 - define the custom region in your template.php file
  • step 2 - add the custom region to your page.tpl.php file

So, lets see how it works.

Step 1 - define the custom region in your template.php file

All themes should have a template.php file contained within the theme folder.

Open the template.php file in your chosen editor and locate the function titled 'function nameoftheme_regions' (where nameoftheme will be the name of the theme to which you are adding a custom region). This will probably be the first function in the file, and should look something like this:

function nameoftheme_regions() {
  return array(
       'header' => t('header'),
       'left' => t('left sidebar'),
       'content' => t('content'),
       'right' => t('right sidebar'),
       'footer' => t('footer')
  );
}

Okay, now just add your custom region so that it looks like the pre-defined regions.