drupaldrupal-7drupal-theming

Can I change different logo for different pages in drupal


I want to change different logo for each different pages in drupal and I also want to hide logo for some pages too.How can I do that?I've already search possible answers and I didn't find any.


Solution

  • As was stated by MilanG, logo is rendered in your page template (default page.tpl.php or theme suggestion) using $logo variable. This variable is set in template_preprocess_page(), and the best way to change it is to use the same preprocess function in your theme:

    function mytheme_preprocess_page(&$variables) {
      $logo_path = '/' . drupal_get_path('theme', 'mytheme') . '/logos/';
      // Alter logo under some conditions
      if ($first_condition) {
        $variables['logo'] = $logo_path . 'logo1.png';
      } elseif ($second_condition) {
        $variables['logo'] = $logo_path . 'logo2.png';
      } elseif ($third_condition) {
        // Hide logo. Your page.tpl.php must contain 
        // something like <?php if ($logo): ?>
        $variables['logo'] = null;
      }
      // etc.
    }