W3Counter

Disable sidebars on certain pages of your site

September 25, 2010

I’ve built several sites for small businesses. In almost all cases, they have a collection of static pages, and a blog on /blog/. I used to use the No Sidebars page template for all the pages.

Thesis 1.8 makes it even easier to disable sidebars on certain areas of your site. With just a few lines of code, you can disable them on any page, post, posts matching a certain criteria, or any archive page (including specific category archives and tag archives).

Some examples

Disable Sidebar everywhere

add_filter( 'thesis_show_sidebars', '__return_false' );

Disable on all ‘pages’ except the Blog page

add_filter( 'thesis_show_sidebars', 'thesify_no_sidebar_except_blog_page' );
function thesify_no_sidebar_except_blog_page() {
    // if it is a page and not the blog page, disable ( return false ).
    if( is_page() && !is_page('blog') )
        return false;
    // else enable
    return true;
}

Only show sidebars on single posts

add_filter( 'thesis_show_sidebars', 'thesify_sidebar_only_single_post' );
function thesify_sidebar_only_single_post() {
    // if it is a single post, enable it ( return true ).
    if( is_single() )
        return true;
    // else disable
    return false;
}

Leave a Comment

Previous post:

Next post: