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.

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:

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.

Leave a Reply

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