Theme Logo is a theme feature, first introduced in Version 4.5. This feature allows themes to add custom logos.
Theme/Custom Logo feature is the recommended method for adding logos in WordPress versus using the Custom Header especially with the built-in schema benefit of itemprop="logo"
microdata for the logo image element.
In this article, I share code that I originally found on John Sundberg’s website, then modified by Tony Eppright, then by Neil Gowran with a little input by Mike Hemberger finally updated with code directly in the Genesis core.
The idea is to replace the logo appearing as CSS background with inline image added via Theme Logo WordPress feature.
While the tutorial has been written for Genesis Sample child theme, it should work with a few adjustments in any Genesis child theme.
Step 1
Edit child theme’s functions.php.
a) Remove the code to add support for custom header and add support for the custom logo instead.
Replace
//* Add support for custom header | |
add_theme_support( 'custom-header', array( | |
'width' => 600, | |
'height' => 160, | |
'header-selector' => '.site-title a', | |
'header-text' => false, | |
'flex-height' => true, | |
) ); |
with
// Add support for custom logo. | |
add_theme_support( 'custom-logo', array( | |
'width' => 600, | |
'height' => 160, | |
'flex-width' => true, | |
'flex-height' => true, | |
) ); |
b) Add
add_filter( 'genesis_seo_title', 'custom_header_inline_logo', 10, 3 ); | |
/** | |
* Add an image inline in the site title element for the logo | |
* | |
* @param string $title Current markup of title. | |
* @param string $inside Markup inside the title. | |
* @param string $wrap Wrapping element for the title. | |
* | |
* @author @_AlphaBlossom | |
* @author @_neilgee | |
* @author @_JiveDig | |
* @author @_srikat | |
*/ | |
function custom_header_inline_logo( $title, $inside, $wrap ) { | |
// If the custom logo function and custom logo exist, set the logo image element inside the wrapping tags. | |
if ( function_exists( 'has_custom_logo' ) && has_custom_logo() ) { | |
$inside = sprintf( '<span class="screen-reader-text">%s</span>%s', esc_html( get_bloginfo( 'name' ) ), get_custom_logo() ); | |
} else { | |
// If no custom logo, wrap around the site name. | |
$inside = sprintf( '<a href="%s">%s</a>', trailingslashit( home_url() ), esc_html( get_bloginfo( 'name' ) ) ); | |
} | |
// Build the title. | |
$title = genesis_markup( array( | |
'open' => sprintf( "<{$wrap} %s>", genesis_attr( 'site-title' ) ), | |
'close' => "</{$wrap}>", | |
'content' => $inside, | |
'context' => 'site-title', | |
'echo' => false, | |
'params' => array( | |
'wrap' => $wrap, | |
), | |
) ); | |
return $title; | |
} | |
add_filter( 'genesis_attr_site-description', 'custom_add_site_description_class' ); | |
/** | |
* Add class for screen readers to site description. | |
* This will keep the site description markup but will not have any visual presence on the page | |
* This runs if there is a logo image set in the Customizer. | |
* | |
* @param array $attributes Current attributes. | |
* | |
* @author @_neilgee | |
* @author @_srikat | |
*/ | |
function custom_add_site_description_class( $attributes ) { | |
if ( function_exists( 'has_custom_logo' ) && has_custom_logo() ) { | |
$attributes['class'] .= ' screen-reader-text'; | |
} | |
return $attributes; | |
} |
Step 2
Add the following in child theme’s style.css:
.wp-custom-logo .title-area { | |
max-width: none; | |
margin-top: 0; | |
} | |
.wp-custom-logo .site-title { | |
text-indent: 0; | |
} | |
.wp-custom-logo .site-title > a { | |
min-height: 0; | |
} | |
.custom-logo-link { | |
display: block; | |
} | |
.custom-logo { | |
vertical-align: top; | |
} |
If your theme does not have the CSS for screen reader text, add:
/* ## Screen Reader Text | |
--------------------------------------------- */ | |
.screen-reader-shortcut, | |
.screen-reader-text, | |
.screen-reader-text span { | |
border: 0; | |
clip: rect(0, 0, 0, 0); | |
height: 1px; | |
overflow: hidden; | |
position: absolute !important; | |
width: 1px; | |
word-wrap: normal !important; | |
} | |
.screen-reader-text:focus, | |
.screen-reader-shortcut:focus, | |
.genesis-nav-menu .search input[type="submit"]:focus, | |
.widget_search input[type="submit"]:focus { | |
background: #fff; | |
box-shadow: 0 0 2px 2px rgba(0,0,0,.6); | |
clip: auto !important; | |
color: #333; | |
display: block; | |
font-size: 1em; | |
font-weight: bold; | |
height: auto; | |
padding: 15px 23px 14px; | |
text-decoration: none; | |
width: auto; | |
z-index: 100000; /* Above WP toolbar. */ | |
} |
Step 3
Go to Appearance > Customize > Site Identity.
Click on “Select logo” button, upload/select your logo image, click on “Skip Cropping” button and finally “Save & Publish”.
References:
http://wpbeaches.com/using-new-custom-logo-theme-support-genesis/
https://sridharkatakam.com/inline-logo-in-genesis/
genesis/lib/structure/header.php
[…] on February 17, 2017: Follow Theme Logo in Genesis instead of this one […]
[…] Theme Logo in Genesis […]
HI Sridhar, Any idea why the logo should be showing on front end but is not.
It’s in the source code but not displaying on the front end.
Strange. The logo is there but not showing:
https://www.staging1.pixelhappy.co/
Protected by login: username: pixelfy password: Happy@4Ever
If you have a moment to take a look.
Thanks.
I see a jpg image logo being used.
working now, then yes? I think it may have been a cache issue in chrome.
Yes, it’s working.
Thanks, Sridhar, now have an inline logo and a fixed mini header upon scroll thanks to you!
Yael
Awesome tutorial! I’ve followed it step by step and uploaded my logo for the title-area but only find an empty
in my source code and no logo on the front end. Any idea what might be happening?
Can you provide the URL of your site?
I am using Altitude Pro.
Customizer:
Selecting a logo and then selecting Image Logo in the drop down the logo is not seen.
Selecting Dynamic Text in the drop down then the logo is seen.
As per the screen sharing session we had, it should not matter what’s selected in the “Use for site title/logo” dropdown. By default, it should not be showing anything and when you click on it, you would see “Dynamic text” ticked.
Hi Sridhar,
With this code is it possible to have BOTH site title and site logo side by side ?
Make these changes:
1) Replace
with
2) Add this sample CSS and tweak further per your design:
Hello and thank you for this tutorial.
I have got the logo to show but the title still shows above the logo and the site description below, how can I remove these?
Many thanks
http://littlewebsiteagency.com
Try adding this in your child theme’s style.css:
Thank you so much for this Sridhar.
This removed the title, the site description is still showing though.
Actually I have now changed the theme so it won’t show but I’ll keep this in mind for the next time I need to add a logo 🙂
[…] this tutorial, I share a modification of the code from Theme Logo in Genesis article to display the site title and image logo (vs as a background) using the WordPress' Theme […]
Hi Sridhar,
Thank you so much for this helpful tutorial.
My logo is pointing from /wp-content/uploads/2017/10/logo.svg
How can I have my logo pointing from /images/logo.svg Or /wp-content/themes/monochrome-pro/images/logo.svg
Thank you in advance for your support.
When i am using the Structured Data Testing Tool to check live data for errors.
i am facing error >>>>
http://example.com/wp-content/uploads/Logo.png (The property logo is not recognized by Google for an object of type WPHeader.)
I’m having trouble doing this in Magazine Pro. I’ve made all the changes, though it doesn’t show anything. Is there anything specific to Magazine Pro that would require this to be slightly modified?
Is this tutorial still relevant for the latest version of Genesis, I am using Executive Pro theme, and the first time I tried this the logo disappeared, it might have been that caching issue you mentioned above, but I wanted to ask about the newest version befroe I attempt it again, thanks for all your help!!!
Hello- this is very helpful, but I’m still seeing the website title and tagline in addition to the new logo. How can I remove that?
Which child theme are you using?