Created
June 13, 2017 02:12
-
-
Save riskiii/fc65b29def62e07f2fdcd75a9ac94b1b to your computer and use it in GitHub Desktop.
Adds hooks immediately before and after Genesis structural wraps.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 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( | |
'header', | |
'menu-primary', | |
'menu-secondary', | |
'site-inner', | |
'footer-widgets', | |
'footer' | |
); | |
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'; | |
ob_start(); | |
do_action( "{$position}_genesis_{$context}_wrap" ); | |
if ( 'open' === $original_output ) { | |
return ob_get_clean() . $output; | |
} else { | |
return $output . ob_get_clean(); | |
} | |
}, 10, 2 ); | |
} | |
} | |
add_hooks_outside_structural_wraps(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment