Site logo

Archived topic

Different sidebar layout for different blog post pages

4 replies · Started by Sharon Steely on October 5, 2015

Viewing posts 1–5 of 5

I use the latest posts as my home page. I used the customizer to set the layout for Blog Sidebar Layout to Content (no sidebars) which is what I want for the home page.

For my archives and categories, I want the left sidebar to show. Since these aren't technically "pages" I don't see a way to edit to turn off global settings.

Here is my home page currently:
http://elnews-new.unm.edu/

Here is a category page, which I want to display with the left sidebar:
http://elnews-new.unm.edu/index.php/category/online/

This is a dev site.

Thanks for your help!

Hi Sharon. You could set the default layout to left sidebar, then use this function in your child theme functions.php file to remove the sidebar on your home page:

add_filter( 'generate_sidebar_layout','generate_custom_sidebar_layout' );
function generate_custom_sidebar_layout( $layout ) {
    // If we are on the home page, no sidebar
    if ( is_home() )
        return 'no-sidebar';

    // Or else, set the regular layout
    return $layout;
 }

Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/

Thanks bdbrown! I just implemented your suggestion and it worked!

I appreciate you sharing the code as-is. My knowledge of pHP is very limited.

Thanks for your help!

And thanks for writing an awesome theme Tom!

cool, thanks.

This archived topic is closed to new replies.