How to get rid of header-image body class when an image logo is not being used in Genesis

Posted on
5/5 - (496 votes)

Fresh install showing site title text in header:

1) You add the code for adding support for custom header in child theme’s functions.php:

add_theme_support( 'custom-header' );

2) Go to Appearance > Header and upload an image.

3) Let’s say you had a change of mind and decided to use text site title and not a logo.

What you should ideally do is go back to Appearance > Header and click on Hide image button (and save, of course).

Let us continue our scenario where in you or the client hasn’t and simply deleted the code added in step 1.

4) Now at Genesis theme settings you’ll find a new Header section with ‘Dynamic text’ as the default setting. Big deal because that’s what we want. But wait, reload your front end and you’ll find the logo image present in the child theme’s images directory.

Clicking ‘Save Settings’ on the Genesis theme settings page with ‘Dynamic text’ as the option wouldn’t help.

The problem is that line 93 in genesis/lib/structure/layout.php,

if ( 'image' === genesis_get_option( 'blog_title' ) || ( get_header_image() && ! display_header_text() ) )

returns true even though theme support for custom header has been removed because the header actually does have the image in the database linked to it that you have uploaded earlier in step 2. Remember that this wouldn’t be the case had the uploaded image been removed prior to deleting the custom header theme support code.

At this stage, there are three options:

Solution 1

This is the simplest method.

a) Do step 1 above. i.e., in functions.php, add

add_theme_support( 'custom-header' );

b) Go to Appearance > Header and remove the image.

c) In functions.php, delete

add_theme_support( 'custom-header' );

Solution 2

Add this in functions.php:

// Removes 'header-image' class from the body_class array
add_filter( 'body_class', 'remove_class' );
function remove_class( $classes ) {

	// search the array for the class to remove
	$unset_key = array_search( 'header-image', $classes );

	if ( false !== $unset_key ) {
		// unsets the class if the key exists
		unset( $classes[$unset_key] );
	}

	// return the $classes array
	return $classes;

}

Source: https://codex.wordpress.org/Function_Reference/body_class#Removing_Classes_By_Filters

Solution 3

Add the following CSS in style.css:

.header-image .site-title > a {
	background: transparent;
	min-height: 0;
	width: auto;
	float: none;
}

.header-image .site-title,
.header-image .site-description {
	text-indent: 0;
}

to get the text title back.