WordPress.org

Support

Support » How-To and Troubleshooting » Hide sidebar when no Widgets in a custom theme

Hide sidebar when no Widgets in a custom theme

  • 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?

    <?php
    if ( is_active_sidebar(1) ) {
    	// Display some text
    } else {
    	// Display none
    };
    ?>

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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?

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

    sidebar.php;

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide sidebar when no Widgets in a custom theme’ is closed to new replies.
Skip to toolbar