Question

I am looking for a way not to show the site logo in my homepage (but on all other pages). I can manage to do this only in the nasty way, using css and display none - however, I would like to avoid that the logo is not loaded on the homepage? functions.php?

best, Aprilia

Was it helpful?

Solution

I had a quick look at the site-branding template part which handles the rendering of the custom logo on the site header. There's a conditional check on two lines against has_custom_logo(), along show title theme mod, which determines, if the custom logo should be rendered or not.

Internally has_custom_logo() calls get_theme_mod( 'custom_logo' ) to figure out, if a custom logo has been set. This means, you can use the theme_mod_{$name} filter to change 1) the value of the theme mod and 2) the result of has_custom_logo().

As code the above would be something like this,

function prefix_disable_logo_on_front_page( $value ) {
    return is_front_page() ? false : $value;
}
add_filter('theme_mod_custom_logo', 'prefix_disable_logo_on_front_page');

OTHER TIPS

You can add the below condition in the header.php file just above the img tag:

<?php if(!is_front_page()){?>
<img src="your_image_path">
<?php } ?>

solved it like this, it works, but seems not very elegant?

function change_logo_on_front($html) {

if(is_front_page()){
      $html = preg_replace('/<img(.*?)\/>/', ' ', $html);
   }
   return $html;
}

add_filter('get_custom_logo','change_logo_on_front');
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top