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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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');
Method 2
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 } ?>
Method 3
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');
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0