To give you extra flexibility with styling your child theme the Genesis Framework gives us Structural Wraps which you can add support for using the code:
add_theme_support( 'genesis-structural-wraps', array( 'header', 'nav', 'subnav', 'site-inner', 'footer-widgets', 'footer' ) );
But every now and then you want to add something between the wrap and the code you are wrapping.
In this case we wanted to add a div directly after the 3 footer widgets before the closing wrap </div>, see the image below for our desired markup.
A look in the genesis/lib/structure/footer.php file where the genesis_structural_wrap is defined showed that there is a filter we can use:
$output = apply_filters( "genesis_structural_wrap-{$context}", $output, $original_output );
In our case the {context} is ‘footer-widgets’ so we can do an add_filter to genesis_structural_wrap-footer-widgets – yes it is important that those hypens at the end are hypens and not underscores.
The $original_output is a little misleading, as it stores whether we are opening or closing the wrap identified by the strings ‘open’ and ‘close’. Using this to target only the closing case, we set about adding our content to $output, which we duly return.
This was just a test so our code creates just a simple div but you could add whatever you need here.
Please note, that I’ve been reliably informed by @GaryJ that this will only work in Genesis 2.1 or later.
You can also see this code on github.
add_filter( "genesis_structural_wrap-footer-widgets", 'jmw_filter_footer_widgets_structural_wrap', 10, 2);
/**
* Filter the footer-widgets context of the genesis_structural_wrap to add a div before the closing wrap div.
*
* @param string $output The markup to be returned
* @param string $original_output Set to either 'open' or 'close'
*/
function jmw_filter_footer_widgets_structural_wrap( $output, $original_output ) {
if( 'close' == $original_output ) {
$output = '<div>Your text here</div>' . $output;
}
return $output;
}
Featured Image: Photo by Alex Smith on Unsplash
Ronald
Hello Jo,
Thanks for this tutorial. However, I want a customize text below footer-widget but above wrap. How can I do that?
I will wait for your response. Thanks! – Ronald
Jo Waltham
Hi Ronald
In the conditional change the ‘close’ to ‘open’ to target when this filter is called when the footer-widgets markup is opened.
Jo