• Hi there,

    I have a main logo which is going to used throughout the website, however, I have a page that I would like to use another logo for instead of the main one.

    What would be my best approach to do this?

    I would assume some JavaScript would probably be best (To replace the image used, dependant on the page I’m on).
    But I wouldn’t know where to enter this or how to write it out correctly.

    Any help would be appreciated.

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Peter,

    It might be easier to just create a new page template that uses the new logo. Then simply use that template for the pages that require the new logo.

    This approach removes the need for the JS.

    Just a thought.

    Mark ??

    Moderator bcworkz

    (@bcworkz)

    Mark’s idea can work, but logos usually are output from the header template, the same file is used for all pages. Having unique header files for each template gets cumbersome and maintaining the header content gets more complicated when many different files are involved.

    JS can work too, but you typically see the old logo briefly before the proper one gets swapped in. Not the best user experience.

    I would dynamically output the proper logo in PHP based on the requested page. The specifics depend on how your theme outputs a logo. In some cases it is a pluggable function. You can redefine the same function is a child theme and it’ll be used instead of the original. Before doing that, see if there is a filter you can hook to alter the image src. Filter hooks are preferable to redefining pluggable functions. In PHP you cannot redefine functions unless the theme dev purposely made the function pluggable. Pluggable function declarations are wrapped in code that’s something like this:

    if ( ! function_exists( 'foobar_theme_logo' ) ):
       //foobar_theme_logo function declaration here
    endif;

    The way code can determine the correct image src varies. You can get the requested object ID with get_queried_object_id(). With the ID, a switch/case structure can determine the correct image src. Or the data can be stored in an array keyed by ID. Get the associated value out of the array. The image src could be saved as post meta, simply get the meta value with the ID. If there is no match or the returned value is empty, just output the default logo.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change logo dependant on page’ is closed to new replies.