I use the Genesis framework on every project because of its speed, security, and ease of customization. There are hundreds of Genesis hooks and filters available that allow you to customize just about anything that you need. On rare occasions, though, I have needed to create my own hook(s) as a workaround.

Full width page headerA great example of needing a workaround is when trying to insert HTML between a container and its immediate descendant .wrap element. By default, Genesis adds a structural wrap to the header, menu-primary, menu-secondary, footer-widgets, and footer elements. I often add it to the .site-inner container as well to help with styling. But sometimes you may need to insert HTML between the structural wrap and its parent container, like when you want a full width page header. There are a few ways to do this, but the cleanest way that I’ve found is to add your own hook. Here’s how:

UPDATE: I have modified the following code based upon a suggestion by Mike Hemberger.  This function now adds hooks both immediately before the opening div and immediately after the closing div of each Genesis structural wrap.
// Prefixing is recommended if you are not using a namespace.
// namespace TimJensen\GenesisStarter\Setup;
* Adds hooks immediately before and after Genesis structural wraps.
* @version 1.1.0
* @return void
function add_hooks_outside_structural_wraps() {
$structural_wraps = array(
foreach ( $structural_wraps as $context ) {
* Inserts an action hook before the opening div and after the closing div for the structural wraps.
* @param string $output HTML markup for opening or closing the structural wrap.
* @param string $original_output Either 'open' or 'close'.
* @return string
add_filter( "genesis_structural_wrap-{$context}", function ( $output, $original_output ) use ( $context ) {
$position = ( 'open' === $original_output ) ? 'before' : 'after';
do_action( "{$position}_genesis_{$context}_wrap" );
if ( 'open' === $original_output ) {
return ob_get_clean() . $output;
} else {
return $output . ob_get_clean();
}, 10, 2 );
view raw functions.php hosted with ❤ by GitHub

Here we have added three twelve new hooks:

New hooks before and after Genesis structural wraps.

And we can use these just like any other WordPress hook. So to accomplish the full width page header you could do something like this:

add_action( 'before_genesis_site-inner_wrap', 'do_full_width_page_header' );
* Adds a div with a background image before the site-inner wrap.
function do_full_width_page_header() {
printf( '<div class="full-width-page-header" style="background: url(\'%s\');"></div>',
wp_get_attachment_image_url( 2623, 'full' )
view raw functions.php hosted with ❤ by GitHub

Simple and clean, right?

Reader Interactions


    • Hi Damien, thanks for your comment! Do you mean why not do something like

      add_filter( 'genesis_structural_wrap-header', 'your_callback_function', 10, 2  );

      instead of generating the filter tag dynamically? Yes, you can definitely do it that way. The way I presented it in this post helps to keep the code DRY (don’t repeat yourself), assuming that you want to reuse it. But if you intent to add a hook before only one of the structural wraps, then you can forego the foreach loop.

      • Yes.

        I think that your functions.php code could be written as:
        `add_filter( ‘genesis_structural_wrap-header’, ‘do_full_width_page_header, 10, 2 );
        function do_full_width_page_header( $output, $original_output ) {
        return sprintf( ”,
        wp_get_attachment_image_url( 2623, ‘full’ )
        ) . $output;

        I don’t think it is any less DRY than using add_action(), though, as a self taught programmer (I studied Electronic Engineering in college many many years ago) I am not really familiar with such good practices.

        I do find add_action() code easier to write because they rarely have parameters to remember to declare and to return.

  1. Ah, I see your DRY point now – especially that the filter may not provide ‘open’ or ‘closed’ to the filter function (because $output could be something other than ‘open’ or ‘closed’). Thanks for the explanation.

    Next I’ll try understand the get_field() replacement function from your other post – once code goes recursive it takes longer to ‘get.’

    • Thanks, Lee. Several months ago I inquired about whether hooks like these would be added to Genesis, and impression I got was probably not. That’s actually what got me thinking about finding a way to do it. I haven’t needed to use this code very often, but there have been a few times where it made things much easier and cleaner.

    • Hey Rob, are you certain that your theme has the structural wrap for site-inner?

      One other thing to check is that the conditional is evaluating to true where you want it to.

  2. Hey Tim – so evidently, I was wrong in my last comment – please feel free to delete it. I had to explicity add support for structural wraps. Once I did that, it worked like a charm. Thanks again for this. I’m going to keep this handy as we do a LOT of Studiopress/template sites with Genesis.

Leave a Reply

Your email address will not be published. Required fields are marked *