Change logo based on taxonomy term I'm trying to change the logo in my header based on the taxonomy term of a page. I have managed to get it working on the taxonomy landing page itself. However, I have content pages that have term references on them which don't pull through the term title.

This the code that allowing me to display the title on the taxonomy page:

$termid = arg(2);
      $term = taxonomy_term_load($termid);
      $title = $term-&gt;name;

      $title = str_replace(' ', '', $title);

      $field_organisation-&gt;field_organisation['und'][0]['tid'];


I am then stripping out the whitespace and printing the value inside an img tag.

I've tried doing this with views and creating a list of all nodes and adding a contextual filter. Yet this seems to only work the other way. So it only displays the image on the node page itself and NOT the taxonomy landing page.

Any help would be much appreciated.

Thanks.
You can make the code work in 2 situations.

$term = menu_get_object('taxonomy_term', 2);
if (empty($term)) {
  if ($node = menu_get_object('node', 1) ) {
    $wrapper = entity_metadata_wrapper('node', $node);
    $term = $wrapper-&gt;field_organisation-&gt;value();
  }
}

if ($term) {
  $title = $term-&gt;name;
  $title = str_replace(' ', '', $title);
}


entity_metadata_wrapper() is the function provided by module Entity