Changing the site logo and name for each section based on path

description

This snippet allows you to override the site logo and site name for sections of your site, based on paths.

usage

As an illustrative example, the following step-by-step approach shows you how to switch the site logo and site name for when users are viewing various sections (based on path)

Step 1 of 1

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

<?php
/**
* This snippet overrides the logo and site name when users
* are viewing certain sections of your site.*/

function _phptemplate_variables($hook, $variables = array()) {
  switch (
$hook) {
    case
'page':
      if ((
arg(0) == 'blog')) {// changes the logo and site name when viewing blogs
       
$variables['site_name'] = 'blog section name'// change the site name
       
$variables['logo'] = '/path/to/newlogo/logo.png'; // change the site logo
     
}
      if ((
arg(0) == 'image')) { // changes the logo and site name when viewing images
       
$variables['site_name'] = 'user section name'// change the site name
       
$variables['logo'] = '/path/to/newlogo/logo.png'; // change the site logo
     
}
      if ((
arg(0) == 'admin')) { // changes the logo and site name when viewing admin pages
       
$variables['site_name'] = 'admin section name'// change the site name
       
$variables['logo'] = '/path/to/newlogo/logo.png'; // change the site logo
     
}
      if ((
arg(0) == 'product')) { // changes the logo and site name when viewing product pages
       
$variables['site_name'] = 'admin section name'// change the site name
       
$variables['logo'] = '/path/to/newlogo/logo.png'; // change the site logo
     
}
      break;
  }

  return
$variables;
}
?>

Loading custom layout files for each section as well as changing the site name and logo

If you also want to load a page-customtpl.php layout file for each section, you can add the line $variables['template_file'] = 'page-custom';.

Here's an example of the earlier snippet that includes a custom page layout option.

<?php
/**
* This snippet loads a custom layout file and
* overrides the logo and site name when users
* are viewing certain sections of your site
* based on path.
*/

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

  return
$variables;
}
?>

More example path arguments you can use

Here are more examples of using the path that you can use to extend out your layouts even further.

arg(0)=="admin"// is /admin

arg(0) =="node"// is /node

arg(0)=="user" // is /user

arg(0)=="node" && arg(1)=="add" // is /node/add

arg(0)=="node" && arg(arg(2)=="edit" // is /node/###/edit

arg(0)=="user" && arg(1)=="add" // is /user/add

arg(0)=="admin" && arg(1)="user" && arg(2)=="create" // is /admin/user/create

arg(0)=="alias" && arg(1)=="alias1" is /alias/alias1

arg(0)=="taxonomy" && arg(1)=="term" && arg(2)=="term#" // is /taxonomy/term/term#

//arg(1)=="comment"

//arg(2)=="reply"

 
 

Drupal is a registered trademark of Dries Buytaert.