- This topic has 11 replies, 4 voices, and was last updated 5 years, 10 months ago by David.
-
AuthorPosts
-
June 26, 2018 at 4:52 pm #609414Todd
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!
June 26, 2018 at 6:51 pm #609450LeoStaffCustomer SupportHi 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-functionThe condition you are looking for should be something like this:
https://codex.wordpress.org/Conditional_Tags#A_PAGE_PageLet me know if you need more info ๐
June 26, 2018 at 8:44 pm #609499ToddI 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; }
June 26, 2018 at 8:47 pm #609501TomLead DeveloperLead DeveloperWhat was the error?
June 26, 2018 at 11:04 pm #609537ToddI 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
June 27, 2018 at 4:12 am #609687DavidStaffCustomer SupportHi Todd, that error says you are declaring the same
tu_custom_category_sidebar_layout
function in another snippet – the names need to be unique.June 27, 2018 at 10:12 am #610023ToddThank 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; }
June 27, 2018 at 10:44 am #610042DavidStaffCustomer SupportHow are you adding the tag? The link provided is a page so doesn’t include tags.
June 27, 2018 at 12:01 pm #610095ToddI 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
June 27, 2018 at 12:18 pm #610107DavidStaffCustomer SupportAah just noticed in your code, you have changed the name of the filter as well this:
custom_generate_sidebar_layout
should begenerate_sidebar_layout
June 27, 2018 at 3:06 pm #610200ToddThis worked. GP rocks again! Much appreciated and Thank you!
June 28, 2018 at 2:19 am #610520DavidStaffCustomer SupportGlad we could help ๐
-
AuthorPosts
- You must be logged in to reply to this topic.