How to Overhang a WordPress Header Image in Genesis

Overhanging Header Logo ImageEvery once in awhile I’m asked to make the header logo image in a WordPress site jut out of the header area so it overlaps whatever is below it.

You might think it’s impossible. It’s not. Look at the image to the right for proof.

To make the header image hang over and stick out of the header area we need to remove the Genesis header action and replace it with a custom header action.

The trick is to remove the default header function and replace it with a new one that adds a second widget area to the header. Using a widget area lets us place a logo image in a text widget then use CSS to make the image pop out of the header box and hang over whatever is below it.

A bonus to replacing the default Genesis theme header function is that we can use a header image slider, a header parallax slider or even replace the header with a video. The options are limited by imagination only.

The Genesis theme header area usually shows a site’s logo image and it usually contains a right header widget area. Below here are two options for replacing this default header:

  1. One full width widget area
  2. Two 50% width widget areas

You can register and add as many widget areas as needed but one or two will meet most needs.

Don’t have Genesis? Get it here. It’s the best WP theme framework I’ve ever used.

Questions this page answers

  • How do I add more widgets to the Genesis header area?
  • How do I make a custom Genesis theme header?
  • How do I Make a two widget header in WordPress?
  • How do I put a header logo image into my Genesis theme so it sticks over the header area?
  • How do I make a transparent header image hover over my menu?
  • How do I make an image in my header that stands out?
  • How do I give my WordPress site a header that displays over the content below the header?

Instructions and caveats

  • Always work on a Genesis child theme.
  • All work is done in /wp-content/theme-name/functions.php and /wp-content/theme-name/style.css.
  • In these examples we remove the site title and site description from display.
  • Use HTML to make the new header clickable.
  • Any code that begins genesis_register_sidebar registers a widget area for use in Appearance > Widgets. You can place it higher up in functions.php to make it display closer to the top of the widget area list in the Widgets admin page.

Option one: one full width widget area

I would use this full width option to replace the header area with a slideshow, video or just a menu.

This header has a widget with the CSS class header-full.

The regular header is completely removed i.e no header image is displayed unless it is placed in the widget area.

  1. Open functions.php
  2. Add this code to the bottom of it:
    // Remove Genesis header and and replace with custom full width header
    
    genesis_register_sidebar( array(
        'id'            => 'header-full',
        'name'          => __( 'Header Area', 'theme-name' ),
        'description'   => __( 'Header widget area', 'theme-name' ),
    ) );
    
    unregister_sidebar( 'header-right' );
    remove_action( 'genesis_header', 'genesis_do_header' ); 
    add_action( 'genesis_header', 'genesis_do_new_header' ); 
    
    function genesis_do_new_header() { 
    
        if ( is_active_sidebar( 'header-full' ) || has_action( 'genesis_header_full' ) ) { 
            echo '<div class="widget-area header-full">'; 
            do_action( 'genesis_header_full' ); 
            dynamic_sidebar( 'header-full' ); 
            echo '</div><!-- end .widget-area -->'; 
        }
    }
  3. Save functions.php
  4. Open style.css
  5. Add this code to the bottom of it:
    .header-full {width:100%!important;float:left!important;clear:both;margin:0;}
    .header-full {position:absolute;z-index:99999!important;}
    #header {height: 100px!important;}
  6. Save style.css.

The second CSS line can be removed if you do not intend the content of the widget area to hang outside of the widget area.

Option two: two widget areas at 50% width each

This is useful when you need somewhere for an image and somewhere for a header menu.

This custom Genesis theme header area has two widgets. One has the CSS class header-left and the other has CSS class header-right.

This option does display the regular custom header image as the background to the wdigets. Remove the line do_action( ‘genesis_custom_header’ ); to stop the WordPress custom header image from displaying.

The height of the header is configured in functions.php with the code:

/** Add support for custom header */
add_theme_support( 'genesis-custom-header', array(
	'width'	 => 940,
	'height' => 120
) );

Check your theme’s CSS for any height values for the header, title or title area.

Replace the header with a custom header

  1. Open functions.php
  2. Add this code to the bottom of it:
    // Remove Genesis header and and replace with custom two widget header
    
    genesis_register_sidebar( array(
        'id'            => 'header-left',
        'name'          => __( 'Left Header', 'theme-name' ),
        'description'   => __( 'Left hand header widget', 'theme-name' ),
    ) );
    
    remove_action( 'genesis_header', 'genesis_do_header' ); 
    add_action( 'genesis_header', 'genesis_do_new_header' ); 
    function genesis_do_new_header() {
    
        do_action( 'genesis_custom_header' );
    
        if ( is_active_sidebar( 'header-left' ) || has_action( 'genesis_header_left' ) ) { 
            echo '<div class="widget-area header-left">'; 
            do_action( 'genesis_header_left' ); 
            dynamic_sidebar( 'header-left' ); 
            echo '</div><!-- end .widget-area -->'; 
        }
    
        if ( is_active_sidebar( 'header-right' ) || has_action( 'genesis_header_right' ) ) { 
            echo '<div class="widget-area header-right">'; 
            do_action( 'genesis_header_right' ); 
            dynamic_sidebar( 'header-right' ); 
            echo '</div><!-- end .widget-area -->'; 
        }
    }
  3. Save functions.php
  4. Open style.css
  5. Add this code to the bottom of it:
    .header-left {width:50%!important;float:left!important;clear:left;margin:0;}
    .header-left {position:absolute;z-index:99999!important;}
    .header-right {width:50%!important;float:right!important;clear:right;margin:0;}
  6. Save style.css.

Wondering why we only register one sidebar and not two? The header-right sidebar already exists in the Genesis parent theme’s functions.php. We only need to restyle it.

How to overlay the header image

We will use the two widget header option to make an image in the header hang over the menu.

Overlapping an image over the menu will obstruct the menu items. We need to make sure the menu items remain clickable so we will use CSS to add a left-margin to the first item in the menu.

We will set a definite pixel width for the header-left widget.

This method removes the Genesis right header widget and adds a new right header widget. Doing it like this keeps the left and right widget areas together in Appearance > Widgets.

The header this creates looks like the one in the image at the top of this page.

Put this code into functions.php

  1. Open functions.php
  2. Add this code to the bottom of it:
    // Remove Genesis header and and replace with custom two widget header
    
    unregister_sidebar( 'header-right' );
    
    genesis_register_sidebar( array(
        'id'            => 'header-left',
        'name'          => __( 'Left Header', 'theme-name' ),
        'description'   => __( 'Left hand header widget', 'theme-name' ),
    ) );
    
    genesis_register_sidebar( array(
        'id'            => 'header-right',
        'name'          => __( 'Right Header', 'theme-name' ),
        'description'   => __( 'Right hand header widget', 'theme-name' ),
    ) );
    
    remove_action( 'genesis_header', 'genesis_do_header' ); 
    add_action( 'genesis_header', 'genesis_do_new_header' ); 
    function genesis_do_new_header() {
    
        do_action( 'genesis_site_title' ); 
        do_action( 'genesis_site_description' );
        do_action( 'genesis_custom_header' );
    
        if ( is_active_sidebar( 'header-left' ) || has_action( 'genesis_header_left' ) ) { 
            echo '<div class="widget-area header-left">'; 
            do_action( 'genesis_header_left' ); 
            dynamic_sidebar( 'header-left' ); 
            echo '</div><!-- end .widget-area -->'; 
        }
    
        if ( is_active_sidebar( 'header-right' ) || has_action( 'genesis_header_right' ) ) { 
            echo '<div class="widget-area header-right">'; 
            do_action( 'genesis_header_right' ); 
            dynamic_sidebar( 'header-right' ); 
            echo '</div><!-- end .widget-area -->'; 
        }
    }
  3. Save functions.php
  4. Open style.css
  5. Add this code to the bottom of it:
    .header-left {width:226px !important;float:left!important;clear:left;margin:0;}
    .header-left {position:absolute;z-index:99999!important;}
    .header-right {width:50%!important;float:right!important;clear:right;margin:0;}
    .first-menu-item {margin-left: 226px;}
  6. Save style.css.

The only difference between the code used here and the code used in Option Two (above) is in the CSS at step 5:

  • CSS class .header-left {} has its width set to 226px instead of 50%. Adjust the value from 123px to a width that matches your overhang image’s width i.e if your image is 200pixels wide then you should change the width of header-left {} to width:200px;.
  • There is a new CSS class selector of .first-menu-item. This has a margin-left attribute which pushes the menu items toward the right. Change 226px to match the width used for .header-left.

Add the images

  1. Go to Appearance > Header.
  2. Select or upload your main header background image (if using one).
  3. Go to Media > Add New.
  4. Upload your overhang image. Copy the upload URL.
  5. Go to Appearance > Widgets.
  6. Find the Left Header widget area. Drag a text widget into it.
  7. Put the following code into the text widget:
    <a href="http://example.com"><img src="http://example.com/wp-content/uploads/image.png" /></a>
  8. Change example.com to your site’s domain name. Change the src URL value to the URL of your image.

Indent the menu

  1. Go to Appearance > Menus.
  2. Click the button at the top of the screen that reads “Screen Options“.
  3. Put a tick next to CSS Classes.
  4. Collapse the screen options menu by clicking Screen Options again.
  5. Edit the first menu item (click the triangle to expand it).
  6. Put first-menu-item in the box below CSS Classes (Optional).
  7. Save the menu.
  8. Reload the site’s frontend.

If we wanted, we could use the header-right widget to add a menu or another image or anything else.

Miscellany

Your theme might have a height specified for the title area. If so you will need to make the widgets display on top of it by adding this to your CSS:

.header-left {
  position:absolute;
  z-index:99999!important;
}

Done!

Did you find this Genesis header guide helpful? Please comment and let me know.

Sharing is caring!

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

33 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
33
0
Would love your thoughts, please comment.x
()
x