Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carasmo/e21ab755085f8c451335bb45bae01d5e to your computer and use it in GitHub Desktop.
Save carasmo/e21ab755085f8c451335bb45bae01d5e to your computer and use it in GitHub Desktop.
Genesis Swap Put Primary Sidebar into Secondary Sidebar location (it's better to use CSS for this)
/* CSS is best and forget the php : see image in the comments. This is only partial css for that layout. */
@media (min-width: 1200px) {
/* ## sidebar-content-sidebar
--------------------------------------------- */
.sidebar-content-sidebar .content-sidebar-wrap {
width: 80%;
float: left;
}
.sidebar-content-sidebar .content {
width: 75%;
padding-left: 5%;
padding-right: 5%;
float: right;
}
.sidebar-content-sidebar .sidebar-primary {
width: 23%;
float: left;
}
.sidebar-content-sidebar .sidebar-secondary {
width: 20%;
padding-left: 1%;
float: right;
}
}
<?php
// don't add
/*
* Option 2: Not a good idea (better is CSS or the one below)
* This is the idea you see mostly doing a Google search except sometimes it misses swapping classes
* and it never covers changing the id (which affects the skip links) and the aria label
* This is why CSS or the first option is better.
*/
// Remove the Primary Sidebar from the Primary Sidebar area.
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
// Remove the Secondary Sidebar from the Secondary Sidebar area.
remove_action( 'genesis_sidebar_alt', 'genesis_do_sidebar_alt' );
// Place the Secondary Sidebar into the Primary Sidebar area.
add_action( 'genesis_sidebar', 'genesis_do_sidebar_alt' );
// Place the Primary Sidebar into the Secondary Sidebar area.
add_action( 'genesis_sidebar_alt', 'genesis_do_sidebar' );
/**
*
* Change Secondary Sidebar with Primary Sidebar Atts
* @since 1.0.0
*
*/
function prefix_swap_secondary_w_primary_sidebar_atts( $attributes ) {
// add original plus extra CSS classes
$attributes['class'] = 'sidebar sidebar-primary aside-area';
$attributes['aria-label'] = __( 'Primary Sidebar', 'textdomain' );
$attributes['id'] = 'genesis-sidebar-primary';
// return the attributes
return $attributes;
}
add_filter( 'genesis_attr_sidebar-secondary', 'prefix_swap_secondary_w_primary_sidebar_atts', 99 );
/**
*
* Change Primary Sidebar with Secondary Sidebar Atts
*
*/
function prefix_swap_primary_w_secondary_sidebar_atts( $attributes ) {
// add original plus extra CSS classes
$attributes['class'] = 'sidebar sidebar-secondary aside-area';
$attributes['aria-label'] = __( 'Secondary Sidebar', 'textdomain' );
$attributes['id'] = 'genesis-sidebar-secondary';
// return the attributes
return $attributes;
}
add_filter( 'genesis_attr_sidebar-primary', 'prefix_swap_primary_w_secondary_sidebar_atts', 99 );
<?php
// don't add
/*
* Option 1:
* This is better accomplished with CSS but this is the better option than whan I found doing a search
* This will swap them and you don't have to concern yourself about changing the classes, ids, aria-labe, and the skip links
*/
remove_action ( 'genesis_after_content', 'genesis_get_sidebar', 10 );
remove_action ( 'genesis_after_content_sidebar_wrap', 'genesis_get_sidebar_alt', 10 );
add_action ( 'genesis_after_content', 'genesis_get_sidebar_alt', 10 );
add_action ( 'genesis_after_content_sidebar_wrap', 'genesis_get_sidebar', 10 );
@carasmo
Copy link
Author

carasmo commented Mar 6, 2017

screen shot 2017-03-05 at 9 25 15 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment