Posts · 17th May 2009 · 26 comments
Drupal’s default 'Footer message' area (to which you can add content via the admin section - Administer > Site configuration > Site information) will not parse PHP.
If, for example, you add a copyright message to your footer message area such as
© Copyright 2009 it'll be fine until the New Year begins and you have to go in and manually change it to
© Copyright 2010. So, instead, it would be great if you could handle the date dynamically using the following PHP code (see http://php.net/date for further PHP date details):
© Copyright <?php echo date('Y'); ?>
However, try adding that to the default 'Footer message' area and it will simply output the entirety of the code as text, ignoring the PHP tags.
So, what to do?
Create a block (
admin/build/block/add) containing the code, set its input format to PHP, and then place that block in the footer region via the main blocks settings page (
admin/build/block). Crazy simple.
Please note - you will need to ensure that you have the 'PHP filter' module enabled. This is not enabled by default in Drupal 6, but is one of the 'Core - optional' modules and can easily be enabled via your site's admin modules section (
Insert the code, containing the PHP, directly into your Drupal theme's
page.tpl.php file. To do so, first open your theme's
page.tpl.php file and locate the footer output, which in Garland looks something like this:
<div id="footer"><?php print $footer_message . $footer ?></div>
Please note - there are actually two things being output here:
$footer_message- which is the output from Drupal's admin 'Footer message' area (
$footer- which is the actual footer region (to which you can add blocks via the main blocks settings page -
Then simply insert your code wherever you'd like the copyright message to appear, for example (in this case we use the copyright symbol's html entity number
© rather than the symbol to ensure correct output - see http://www.w3schools.com/tags/ref_entities.asp for further details):
<div id="footer">© Copyright <?php echo date('Y'); ?><?php print $footer_message . $footer ?></div>
which results in: