Last active
October 5, 2020 18:16
-
-
Save bryanwillis/c26c2563ca3c71ddea87 to your computer and use it in GitHub Desktop.
Adding genesis-structural-wrap-support to Bootstrap Genesis
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 | |
/** | |
* Module: Bootstrap Genesis Plugin - Structural Wraps | |
* Author: Bryan Willis | |
*/ | |
/** | |
* Add theme support for structural wraps | |
*/ | |
function gb3_add_theme_support_structural_wraps() { | |
add_theme_support( 'genesis-structural-wraps', | |
array( | |
'menu-primary', | |
'menu-secondary', | |
'footer', | |
'site-inner', | |
'header' | |
) | |
); | |
} | |
/** | |
* Filter genesis_attr_structural-wrap to use BS .container-fluid classes | |
*/ | |
add_filter( 'genesis_attr_structural-wrap', 'bsg_attributes_structural_wrap' ); | |
function bsg_attributes_structural_wrap( $attributes ) { | |
$attributes['class'] = 'container'; | |
return $attributes; | |
} | |
/** | |
* Replacement helper function to dynamically switch | |
* change .container to .container-fluid classes | |
* | |
* Useage: add_filter( 'genesis_structural_wrap-{$context}', 'bsg_wrap_container_fluid'); | |
*/ | |
function bsg_wrap_container_fluid( $output, $original_output ) { | |
if ( $original_output == 'open' ) { | |
$output = sprintf( '<div %s>', genesis_attr( 'container-fluid' ) ); | |
} | |
return $output; | |
} |
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 | |
/** | |
* Helper function to apply to all areas | |
* | |
* Useage: bsg_wrap_all_container_fluid() | |
*/ | |
function bsg_container_fluid_all() { | |
$genesis_atts = array( | |
'menu-primary', | |
'menu-secondary', | |
'footer', | |
'site-inner' | |
); | |
foreach ( $genesis_atts as $context ) { | |
$context = "genesis_structural_wrap-$context"; | |
add_filter( $context, 'bsg_wrap_container_fluid', 16, 2 ); | |
} | |
} |
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 | |
/** | |
* Example using helper from container-fluid-all.php | |
* to return all fluid wraps for the home page. | |
* Include this in your functions.php | |
*/ | |
function bsg_container_fluid_all_is_home() { | |
if ( is_home() ) { bsg_wrap_all_container_fluid(); } | |
} | |
add_action('genesis_before', 'bsg_container_fluid_all_is_home'); |
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 | |
/** | |
* Template Name: Full Width Landing Page | |
* Description: Creates a full width page with with no content wrap and container-fluid menu wraps. | |
* | |
* @package WordPress | |
* @subpackage Bootstrap Genesis | |
* @author Bryan Willis | |
*/ | |
/** | |
* Remove a structural wrap on a page content or post and | |
* force full width content. Useful for landing pages. | |
*/ | |
add_action( 'genesis_meta', 'bsg_is_home_force_layout_full_width_no_wrap' ); | |
function bsg_is_home_force_layout_full_width_no_wrap() { | |
if (is_home() || is_front_page()) { | |
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' ,11 ); // force full width layout | |
add_filter( 'genesis_structural_wrap-menu-primary', 'bsg_wrap_container_fluid', 16, 2); // .container-fluid primary menu | |
add_filter( 'genesis_structural_wrap-menu-secondary', 'bsg_wrap_container_fluid', 16, 2); // .container-fluid secondary menu | |
add_filter( 'genesis_structural_wrap-site-inner', '__return_empty_string' ); // remove .container | |
remove_filter( 'genesis_attr-content-sidebar-wrap', 'bsg_add_markup_class' ); // remove .row | |
remove_filter( 'genesis_attr-content', 'bsg_add_markup_class' ); // remove .col-* classes from .content | |
} | |
} | |
/** | |
* Custom body class | |
*/ | |
add_filter( 'body_class', 'bsg_custom_template_body_class' ); | |
function bsg_custom_template_body_class( $classes ) { | |
$classes[] = 'landing-page'; | |
return $classes; | |
} | |
genesis(); |
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 | |
/** | |
* Template Name: Jumbotron Wrap | |
* Description: Template with a jumbotron area | |
* | |
* @package WordPress | |
* @subpackage Bootstrap Genesis | |
* @author Bryan Willis | |
*/ | |
add_theme_support( 'genesis-structural-wraps', | |
array( | |
'menu-primary', | |
'menu-secondary', | |
'footer', | |
'site-inner', | |
'jumbotron-outer' | |
) | |
); | |
// Remove page title | |
remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); | |
// Remove default Genesis loop | |
remove_action( 'genesis_loop', 'genesis_do_loop' ); | |
// Add new custom loop | |
add_action( 'genesis_loop', 'bsg_landing_content' ); | |
/** | |
* Landing Page Content | |
*/ | |
function bsg_child_custom_loop() { ?> | |
<!-- Custom Content --> | |
<?php } | |
/* | |
// Register Widget In functions.php | |
add_action('widgets_init', 'register_jumbotron_sidebar'); | |
function register_jumbotron_sidebar() { | |
$jumbotron = array( | |
'id' => 'jumbotron-widget', | |
'name' => __( 'Jumbotron', 'gb3' ), | |
'description' => __( 'This is located inside the jumbotron header.', 'genesis' ), | |
'class' => '', | |
'before_widget' => '<div id="%1$s" class="%2$s">', | |
'after_widget' => '</div>', | |
'before_title' => '<h1>', | |
'after_title' => '</h1>', | |
); | |
register_sidebar( $jumbotron ); | |
} | |
// */ | |
add_action( 'genesis_after_header', 'do_jumbotron_widget_area' ); | |
function do_jumbotron_widget_area() { | |
do_action('jumbotron'); | |
} | |
add_action( 'jumbotron', 'jumbotron_widget_area_callback' ); | |
function jumbotron_widget_area_callback() { | |
if ( is_active_sidebar( 'jumbotron-widget-area' ) ): ?> | |
<?php genesis_structural_wrap( 'jumbotron-outer' ); ?> | |
<div <?php echo genesis_attr( 'jumbotron' ); ?>> | |
<?php genesis_structural_wrap( 'jumbotron-inner' ); ?> | |
<?php dynamic_sidebar( 'jumbotron-widget-area' ); ?> | |
<?php genesis_structural_wrap( 'jumbotron-inner', 'close' ); ?> | |
</div> | |
<?php genesis_structural_wrap( 'jumbotron-outer', close ); ?> | |
<?php endif; | |
} | |
genesis(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment