WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. diHobbes
    Member
    Posted 1 year 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?

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

    Thank you!

  2. marcelle42
    Member
    Posted 1 year 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. alchymyth
    Forum Moderator
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic