Community Documentation

Customizing the site logo and name based on path

Last updated August 26, 2009. Created by Dublin Drupaller on June 23, 2007.
Edited by bekasu, bryan kennedy. Log in to edit this page.

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

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x, Drupal 6.x
Audience
Themers

Theming Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.