Hide sidebar when no Widgets in a custom theme (3 posts)

  1. diHobbes
    Posted 2 years ago #

    When I hide the widgets in my custom theme, the sidebar is still there.

    I know here it's explained how to do it: Function reference

    Is this the code I'm supposed to use? Where should I paste it?

    if ( is_active_sidebar(1) ) {
    	// Display some text
    } else {
    	// Display none

    Thank you!

  2. marcelle42
    Posted 2 years ago #

    Even if the sidebar is empty, you may still have a sidebar div taking up space, or the main content div may not be wide enough. Can you provide a link to your site?

  3. Michael
    Part-Time Forum Moderator
    Posted 2 years ago #

    for axample code, look into Twenty Twelve which does exactly the same;


    in functions.php there is some code to add a special body_class if the sidebar is empty;

    in style.css there are styles to do what @marcelle42 pointed out.

Topic Closed

This topic has been closed to new replies.

About this Topic