Archived topic
GP / Sidebar / Search result page
9 replies · Started by Jan on April 25, 2022
Hi David,
how would you go about hiding the sidebar on non-static pages such as search results or blog page?
The issue is that dynamic pages have no page ID which I can use for a custom CSS snippet to say "display: none".
Any thoughts are highly welcome.
Best,
Jan
PS: Unfortunately, this existing threat from Jeff was not of much help.
Hi Jan,
We would recommend using a Layout Element to hide the entire sidebar on certain pages.
Reference to the Layout Element: https://docs.generatepress.com/article/layout-element-overview/
Specifically, through a Layout Element, you may set a sidebar layout for any page through the Display rules of the Layout Element. (The search page can be set in the Display rules.)
Hope this helps! Kindly let us know if further assistance would be needed. :)
Hi Fernando,
this is a great advise. I did...
- set up a new Layout Element and
- set the Sidebar layout to "Content (no sidebars)" and
- applied this rule to Search Result and No Search Results (Location)
The sidebar, however, is still there. Are Search Results indeed the correct location for this page?
Any advise on how to identify the page type would be much appreciated.
Thanks,
Jan
Hi Jan,
I tried checking your Search Page and No Search Results page and these pages no longer have a sidebar.
The linked page isn’t the default Search or no search results page. This seems to be a search page from BBPress.
You can try activating the Layout Element through generate_layout_element_display: https://docs.generatepress.com/article/generate_layout_element_display/
For instance, for research, it seems that BBPress has this function to check if the page is a search page bbp_is_search(): https://www.buddyboss.com/resources/reference/functions/is_bbpress/
In this case, you can try adding this snippet:
add_filter( 'generate_layout_element_display', function( $display, $element_id ) {
if ( 123 === $element_id && ( bbp_is_search() || bbp_is_search_results() ) ) {
$display = true;
}
return $display;
}, 10, 2 );
Kindly replace 123 with the ID of the Element.
How to get the id: https://share.getcloudapp.com/X6uEj0zg
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Adding it through Code Snippets should work.
Alternatively, for search pages, you may try adding this CSS in Appearance > Customize > Additional CSS:
body.bbp-search .sidebar{
display:none;
}
body.bbp-search div#primary {
width:100%;
}
Kindly let us know how it goes. :)
Wow. This is on the spot. Many thanks Fernando.
I went with the custom CSS snippet.
Question: From a performance standpoint, is the php-filter or CSS snippet the better way to go?
Best,
Jan
Hi there,
I doubt you would notice any performance difference between either method.
But the PHP Snippet method in theory will be more performant.
First it will cost a couple of more operations - thats a negative.
In return, that page won't require the operations to generate the sidebar or the widgets within it.
Which will result in less HTML for the browser to download.
So i would generally say go with the PHP but as its BB Press and i seen that do some unexplainable stuff, if the CSS works then take that as a win :)
Many thanks David.
I sense you intended to say "they do some unexplainable stuff" correct?
Cheers,
Jan
Yeah = i think so lol. Perhaps i can try again :)
Some functions that run perfectly well on another template doesn't always work as desired with BB Press. So the CSS is probably the more reliable option,
Cool. That's how we do it then.
Thanks again
You're welcome