• Hi,
    I’m not very knowledgeable on code, so excuse me if it’s a simple question:

    I would like to know how to make the sidebar on my website disappear when you are not on the main page.
    For exemple, I would like to be able to see a gallery using the full width of the theme but still keep the regular post with the sidebar active.

    here’s my website: https://www.utopieselective.com

    thanks a lot!

Viewing 10 replies - 1 through 10 (of 10 total)
  • If you want the side bar to only apear on the main page, go to all the other pages. On each page look down the right side for “Template”. on every page that you do not want the side bar select “Fulle Width- no side bar”.

    Thread Starter utopie selective

    (@utopie-selective)

    Thanks for the quick answer!

    But sadly, I don’t see the ‘Template’ box when I’m editing a page, and it’s not available for check on the ‘screen option’ menu.

    here’s a quick screenshot of what my “edit page” looks like.

    could it be a plugin that I need to activate?

    I would check just to be safe but if it works on you main page it is probably activated.
    You could switch to a theme that allows you more flexability in the widget area. The Twenty Thirteen theme only gives you the choice of on the side of every page or in the footer of every page.

    Remove <?php get_sidebar(); ?> on index.php and page.php.

    Update
    Or replace if ( is_active_sidebar( 'sidebar-2' ) ) : ?> on siderbar.php with
    if( is_single() && ( is_active_sidebar( 'sidebar-2' ) ) ) : ?>

    If you start editing the code you might run into problems the next time the Twenty Thirteen theme people do an upgrade. It would be better and safer to creat a Child Theme. then you can modify it to your heart’s content.

    Thread Starter utopie selective

    (@utopie-selective)

    Ok thanks,

    HDSusanto: I did your first suggestion, and it works, but it keeps the space allowed for the sidebar, so i don’t get the full page width I want. I then tried the second suggestion, and my sidebar just vanished from everywhere. It’s close! but not cigar.

    Lapsanders:
    I think you have the solution, I just need to get there I guess!

    I made a child theme,
    but lost all customization made by the style and style:twenty thirteen plugins. If possible I would love to keep them! Or I really need to do them again?

    I found this topic too explaining how to get back the missing template box, I’ll look into that

    lupine99

    (@lupine99)

    I have yet to find a solution to a similar problem, this post is closest. I would like to remove the sidebar and sidebar area from my page.php template but keep it for my other page template.

    I removed the get_sidebar() call from page.php and it does remove the widget but keeps the space allocated for it.

    Any thoughts are greatly appreciated!

    Did you ever solve this problem?

    I’d like to do the same thing.

    Regarding @hdsusanto’s code. It actually should be a negative call for “is single” if you want it on the main page. This worked for me. (But still leaves the blank space on single pages instead of using the full width.)

    if ( ! is_single() && is_active_sidebar( 'sidebar-2' ) ) : ?>

    Lots of googling and I fixed the problem. Basically, you need to stop functions.php from assigning the “sidebar” “body_class” to the body element. The only way to do that is to re-write the function. However, since it is better to use child themes, you have to first remove the previous function and then add a new one. The new one should not write “sidebar” if the page is a single post. This code works for me:

    /**
     * Remove the default filter.
     */
    function remove_twentythirteen_body_classes(){
    	remove_filter( 'body_class', 'twentythirteen_body_class' );
    }
    add_action('init', 'remove_twentythirteen_body_classes');
    
    /**
     * Extend the default WordPress body classes.
     */
    function twentythirteen_child_body_class( $classes ) {
    	if ( ! is_multi_author() )
    		$classes[] = 'single-author';
    
    /**
     * the && ! is_single() at the end of this is the only real change to the function.
     */
    	if ( is_active_sidebar( 'sidebar-2' ) && ! is_attachment() && ! is_404() && ! is_single() )
    		$classes[] = 'sidebar';
    
    	if ( ! get_option( 'show_avatars' ) )
    		$classes[] = 'no-avatars';
    
    	return $classes;
    }
    add_filter( 'body_class', 'twentythirteen_child_body_class' );
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Sidebar: Make it only appear on the main page’ is closed to new replies.