2

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.

  • Are "Groups" and "Members" just static pages? If so, have you tried using the is_page() conditional? – Chip Bennett Nov 7 '13 at 18:59
  • there are static pages for the main groups and members pages.. but these ones are buddypress generated subpages.. I foudn that the post type was the only way to distinquish them.. and that's working, but I don't know what code to use to remove that widget area once i'm there (in the last 2 if conditions) – Damon Nov 7 '13 at 19:17
0

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');
0

What you can do is force a full-width layout conditionally.

This code works in Genesis child themes only.

add_filter( 'genesis_pre_get_option_site_layout', 'wpsites_full_width_layout' );
function wpsites_full_width_layout( $opt ) {
if ( is_singular(array('bp_group', 'bp_group') ) ) {
$opt = 'full-width-content'; 
return $opt;
    } 
}

Source: wpsites.net

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.