Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothyjensen/b77138c0c265244df1e0e436c5b6bbaf to your computer and use it in GitHub Desktop.
Save timothyjensen/b77138c0c265244df1e0e436c5b6bbaf to your computer and use it in GitHub Desktop.
Insert HTML before or after the Genesis structural wrap for the given contextual area.
<?php
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" and "after_genesis_{$context}_wrap" events.
*
* @since 1.0.0
*
* @return array
*/
$structural_wraps = apply_filters( 'add_outside_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_outside_structural_wrap_filter', 10, 2 );
}
}
/**
* Do the before and after Genesis structural {$context} wrap filters.
*
* @since 1.0.0
*
* @param string $output HTML output
* @param string $original_output Original output
*
* @return string
*/
function do_outside_structural_wrap_filter( $output, $original_output ) {
$context = str_replace( 'genesis_structural_wrap-', '', current_filter() );
if ( 'open' == $original_output ) {
/**
* 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", '' );
return $before_wrap_html . $output;
} elseif ( 'close' == $original_output ) {
/**
* Fire the "after_genesis_{$context}_wrap" filter event, which will
* insert any returned HTML after the contextual area's `</div>`.
*
* @since 1.0.0
*
* @param string $output HTML output
* @param string $context The contextual area
*
* @return string
*/
$after_wrap_html = apply_filters( "after_genesis_{$context}_wrap", '' );
return $output . $after_wrap_html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment