Customising the site logo and name based on path

description

This snippet allows you to load a custom layout file and override the site logo and site name based on path.

Thanks to thomasmurphy for contributing the original snippet.

usage

As an illustrative example, the following step-by-step approach shows you how load a custom blog page layout file and switch the site logo and site name for when users are viewing blogs.

Step 1 of 2

  1. make a copy of your page.tpl.php file and rename it to be page-blog.tpl.php.
  2. Using a text editor like notepad.exe or equivalent, modify the layout of page-blog.tpl.php file to suit your desires
  3. Upload your new page-blog.tpl.php layout file to your active theme folder

Step 2 of 2

  1. Using a text editor like notepad.exe or equivalent, paste the snippet below into your template.php file.
  2. Upload your edited template.php file to your active theme folder and your new layouts will take effect automatically

<?php
/**
* This snippet loads a custom page-blog.tpl.php layout file and
* overrides the logo and site name when users
* are viewing blogs.
*/

function _phptemplate_variables($hook, $variables = array()) {
  switch (
$hook) {
    case
'page':
      if ((
arg(0) == 'blog')) {
       
$variables['template_file'] = 'page-blog'; // loads the custom page-blog.tpl.php file
       
$variables['site_name'] = 'blog section name'// change the site name
       
$variables['logo'] = '/path/to/newlogo/logo.png'; // change the site logo
     
}
      break;
  }

  return
$variables;
}
?>

notes

 
 

Drupal is a registered trademark of Dries Buytaert.