Created
March 24, 2017 18:40
-
-
Save hellofromtonya/48f0823f6d32981766ba968bfd6537de to your computer and use it in GitHub Desktop.
Insert HTML before the Genesis structural wrap for the given contextual area.
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
add_action( 'genesis_meta', 'process_structural_wrap_handler' ); | |
/** | |
* Process the structural wrap handler. | |
* | |
* @since 1.0.0 | |
* | |
* @return void | |
*/ | |
function process_structural_wrap_handler() { | |
/** | |
* Filter the contextual areas to add the "before_genesis_{$context}_wrap" event | |
* | |
* @since 1.0.0 | |
* | |
* @return array | |
*/ | |
$structural_wraps = apply_filters( 'add_before_structural_wrap_context_filter', get_theme_support( 'genesis-structural-wraps' ) ); | |
if ( ! is_array( $structural_wraps ) || ! $structural_wraps[0] ) { | |
return; | |
} | |
foreach( (array) $structural_wraps[0] as $context ) { | |
add_filter( "genesis_structural_wrap-{$context}", 'do_before_structural_wrap_filter', 10, 2 ); | |
} | |
} | |
/** | |
* Do the before Genesis structural {$context} wrap. | |
* | |
* @since 1.0.0 | |
* | |
* @param string $output HTML output | |
* @param string $original_output Original output | |
* | |
* @return string | |
*/ | |
function do_before_structural_wrap_filter( $output, $original_output ) { | |
if( 'open' != $original_output ) { | |
return $output; | |
} | |
$context = str_replace( 'genesis_structural_wrap-', '', current_filter() ); | |
/** | |
* Fire the "before_genesis_{$context}_wrap" filter event, which will | |
* insert any returned HTML before the contextual area's `<div class="wrap">`. | |
* | |
* @since 1.0.0 | |
* | |
* @param string $output HTML output | |
* @param string $context The contextual area | |
* | |
* @return string | |
*/ | |
$before_wrap_html = apply_filters( "before_genesis_{$context}_wrap", $output, $context ); | |
return $before_wrap_html . $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment