Archived topic
bulk edit sidebar layouts
11 replies · Started by Todd on June 26, 2018
Is there a way to change sidebars layouts (go from none to right side bar on multiple pages) for a set of pages with a bulk edit feature that I have seen in some themes. Is there a snippet I can add for this? Thank you!
Hi Todd,
Funny that you are asking for this. GP 1.7 (currently in private Alpha) has the exact feature that will accomplish this easily.
The beta should be public sometimes soon if you can hold off for a bit.
If not, then we'd have to use this filter for now:
https://docs.generatepress.com/article/sidebar-layout/#using-a-function
The condition you are looking for should be something like this:
https://codex.wordpress.org/Conditional_Tags#A_PAGE_Page
Let me know if you need more info :)
I need to try it now, but glad to hear that it will be in 1.7! I added the following and it is giving me an error, do I have something wrong?
add_filter( 'generate_sidebar_layout','tu_custom_category_sidebar_layout' );
function tu_custom_category_sidebar_layout( $layout )
{
// If we are on a category, set the sidebar
if ( in_category( '289' ) )
return 'no-sidebar';
// Or else, set the regular layout
return $layout;
}
What was the error?
I get the following:
Fatal error: Cannot redeclare tu_custom_category_sidebar_layout() (previously declared in /home/curious9/public_html/tvtg164363/wp-content/plugins/code-snippets/php/snippet-ops.php(352) : eval()'d code:2) in /home/curious9/public_html/tvtg164363/wp-content/plugins/code-snippets/php/snippet-ops.php(352) : eval()'d code on line 11
Hi Todd, that error says you are declaring the same tu_custom_category_sidebar_layout function in another snippet - the names need to be unique.
Thank you. I changed that and it is not creating an error now, but this still does not seem to be working to have a right sidebar show up on pages tagged. I put the page that I have tagged in the original forum submission. The snippet is below:
add_filter( 'custom_generate_sidebar_layout','tc_custom_category_sidebar_layout' );
function tc_custom_category_sidebar_layout( $layout )
{
// If we are on a category, set the sidebar
if ( has_tag( 'sidebar' ) )
return 'right-sidebar';
// Or else, set the regular layout
return $layout;
}
How are you adding the tag? The link provided is a page so doesn't include tags.
I have a snippet that adds categories and tags to pages. But I also tried it on a test post page here and the sidebar does not show up. http://tvtg164363.vortechsgroup.com/qwik-post-1
Aah just noticed in your code, you have changed the name of the filter as well this: custom_generate_sidebar_layout should be generate_sidebar_layout
This worked. GP rocks again! Much appreciated and Thank you!
Glad we could help :)