Today I worked on a few customizations in https://crew212.com/ and one of the tasks was to remove the hyperlink for the logo in the site header on the front page but keep it intact (linking to the homepage) on all other inner pages.
The site was using the default custom header feature of WordPress for the logo display. The logo is set as a background image in this method.
For the task at hand, I’ve turned off the custom header and added the following code per the Theme Logo in Genesis tutorial and adjusted the CSS.
remove_theme_support( 'custom-header' );
// Add support for custom logo.
add_theme_support( 'custom-logo', array(
'width' => 800,
'height' => 420,
'flex-width' => true,
'flex-height' => true,
) );
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() ) {
if ( is_front_page() ) {
// get the URL of theme logo.
$custom_logo_id = get_theme_mod( 'custom_logo' );
$image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
$inside = sprintf( '<span class="screen-reader-text">%s</span><img src="%s" class="custom-logo" itemprop="logo" />', esc_html( get_bloginfo( 'name' ) ), $image[0] );
} else {
$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;
}