Archived topic
Changing layout sidebars with a hook
6 replies · Started by Alberto on March 19, 2018
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.
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.
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
It would be the Sidebar/Content option.
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.
Never mind, I've seen how to fix it here: https://docs.generatepress.com/article/allow-sidebars-sections/
Glad you figured out!