I’m trying to remove a widget area called ‘Primary’ from a certain page on a site. This is the function where I manage the sidebars:
//ADD CATEGORIES IN SIDEBAR OF SINGLE POST TYPE
add_action( 'genesis_sidebar', 'add_mysite_sidebar' );
function add_mysite_sidebar() {
if( get_post_type() == 'post' ){
dynamic_sidebar( 'News Categories' );
} else if( get_post_type() == 'events' ){
dynamic_sidebar( 'Event Categories' );
} else if( get_post_type() == 'documentlibrary' ){
dynamic_sidebar( 'Document Categories' );
} else if( get_post_type() == 'bp_members' ){
include(members_sidebar.php);
unregister_sidebar( 'sidebar' );
dynamic_sidebar( 'Members Widget' );
} else if( get_post_type() == 'bp_group' ){
include(groups_sidebar.php);
unregister_sidebar( 'sidebar' );
dynamic_sidebar( 'Groups Widget' );
}
}
I need to remove the ‘Primary’ widget area on the groups and members pages, but I don’t see how to do it, and on the front end the widgets in that widget area are not in any overall container otherwise I could just hide it.
2 Answers
Since you are using Genesis, why don’t you just use the Layout that doesn’t contain Primary Sidebar? The layout option should be available right below the editor (as a meta box).
If you still need code, use plain CSS to remove the sidebar area.
function remove_primary_sidebar() {
//Only if Pages with the following IDs
if (is_page(array('1', '2', '3'))) { ?>
<style type="text/css">
.sidebar-primary {display:none !important;}
</style>
<?php }
}
add_action('wp_head', 'remove_primary_sidebar');