Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created March 24, 2017 18:40
Show Gist options
  • Save hellofromtonya/48f0823f6d32981766ba968bfd6537de to your computer and use it in GitHub Desktop.
Save hellofromtonya/48f0823f6d32981766ba968bfd6537de to your computer and use it in GitHub Desktop.
Insert HTML before the Genesis structural wrap for the given contextual area.
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