[Resolved] Changing layout sidebars with a hook

Home Forums Support [Resolved] Changing layout sidebars with a hook

Home Forums Support Changing layout sidebars with a hook

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #523831
    Alberto

    Hello.
    I’m trying to change the layout in a particular page using this code in functions.php

    function dom_barra_en_especialidades( $layout ){
        if ( is_page('the-slug') ){
            return 'left-sidebar';
        } else {
            return $layout;
        }
    }
    add_filter( 'generate_sidebar_layout','dom_barra_en_especialidades' );

    The default setting is to Content with no sidebars, but I want the left sidebar in that page. I’m still getting the default layout.
    Where I’m getting wrong?

    Thanks in advance.

    #524141
    Leo
    Staff
    Customer Support

    Hi there,

    Is it just a static page?

    If so you can just use the sidebar metabox on that page:
    https://docs.generatepress.com/article/sidebar-layout/#different-sidebar-layouts-for-individual-pages-and-posts

    Let me know if this helps.

    #524310
    Alberto

    Hi Leo.
    Yes, is a static page, and Yes, I’ve just tried the sidebar metabox but I can’t see the left sidebar in the page layout.

    Regards

    #524623
    Leo
    Staff
    Customer Support

    It would be the Sidebar/Content option.

    #525178
    Alberto

    Hello
    Ok, It seems there’s an issue using Sections with this.
    If I set Sidebar/Content in the metabox in the page and I don’t use Sections, it actually shows the left sidebar. But if I use Sections, the sidebar is not displayed.
    Is there a way to solve this?

    Regards.

    #525180
    Alberto

    Never mind, I’ve seen how to fix it here: https://docs.generatepress.com/article/allow-sidebars-sections/

    #525456
    Leo
    Staff
    Customer Support

    Glad you figured out!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.