I am switching my Genesis theme over to use WordPress’ 4.5 custom-logo function. It was simple to do:
add_theme_support( 'custom-logo', array(
'width' => 861,
'height' => 130,
'flex-width' => true,
'flex-height' => true,
) );
However, I do not see a way in which to provide a default logo (which would be under theme/images/header.svg
where customer-header
had had an option like:
add_theme_support( 'custom-header', array(
'default-image' => get_stylesheet_directory_uri() . '/images/header.png',
...
How can I achieve what I am trying to do? I am willing to edit the child theme, of course.
1 Answer
When you display the custom logo you can check if is set, if not you display another image. You can achieve this with the following code featured in the documentation. I adapted it to suit your needs:
$custom_logo_id = get_theme_mod( 'custom_logo' );
$logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );
if ( has_custom_logo() ) {
echo '<img src="'. esc_url( $logo[0] ) .'">';
} else {
echo '<img src="'. get_stylesheet_directory_uri() . '/images/header.png' .'">';
}