Archived topic
Remove sidebar from custom archive page
17 replies · Started by Silvano on June 22, 2020
I built a website for commerce and auctions. Each of these have their own archive page (product archive and product archive auction). I need to remove the sidebar from the product archive auction page.
I got with this filter:
add_filter( 'generate_sidebar_layout', function( $layout ) {
global $product;
if ( method_exists( $product, 'get_type' ) && $product->get_type() == 'auction' ) {
return 'no-sidebar';
}
return $layout;
} );
But the sidebar space continues. Could you help me with that? I wanted the product area to take the entire width.
Hi there,
Any chance you can link us to the site in question?
You can edit the original topic and use the private URL field.
Let me know :)
Hi Leo,
I have this demo:
https://silper.net.br/artauction/leiloes/
where:
loja link = store
leilões link = auction
the archive page for auctions is a copy of woocommerce product-archive page renamed to product-archive-auction used by the plugin Wocommerce Simple Auction to archive auction separated from regular products
I tried remove sidebar in this archive with various conditions tag, but I got sucess only with that function.
Is the sidebar layout in the WooCommerce panel already set to no sidebar?
https://docs.generatepress.com/article/woocommerce-overview/#shop
Yes I did, but in this case sidebar is removed from shop page too and I don't want this. I want remove from auctions archive only. :/
That's strange, can you try this?:
add_filter( 'generate_sidebar_layout', function( $layout ) {
global $product;
if ( method_exists( $product, 'get_type' ) && $product->get_type() == 'auction' ) {
return 'no-sidebar';
}
return $layout;
}, 100 );
Any change?
Hi Tom,
Unfortunately, nothing has changed.
With this condition used by filter I was able to remove the sidebar only on the auction archive page, but the row does not expand to full width.
Do you have a sidebar option set in Customize > Layout > WooCommerce? Or is it set to inherit?
Is set to left sidebar (sidebar-content)
As you can see in my demo:
https://silper.net.br/artauction
the store page(loja) continues with the sidebar and the auction (leilões) is without the sidebar but the sidebar area is still reserved.
It could be that $product->get_type() is available too late during the page load. For example, your <body> element still has the left-sidebar class, so at that point, the above filter isn't being read. It's not until the content area that the sidebar is removed.
I wonder if there's another condition you can try?
Hi,
I got the desired result by changing the permanent links to default, and then I used the "is_page" to select from page ID, it worked. But in this case the page url shows the ID instead of the name... My client will not like this. : /
Other than that I tried several combinations but the only one that returned a result close to the desired one was this one. The others I did removed the sidebar and adjusted the row to full width but both on the store page and on the auction page.
The current archive page is just a copy of product-archive.php renamed to product-archive-auction.php, perhaps a good way out of this is to build a custom archive page for this product type.
You can actually is is_page( 123 ) along with having pretty permalinks - no need to set them to default in order for it to work.
I know that, but the conditional only worked when i changed the parmalinks to pattern
Hmm, I wonder if you could use is_product_category()?: https://docs.woocommerce.com/document/conditional-tags/#section-5
Hi Tom,
It doesn't work either.
From what I've seen, auction is a term in the product_type taxonomy
I tried it with terms_exists (auction, product_type), this removes both shop archive and auction archive either.
I contacted Woocommerce Simple Auction plugin support ... I'll wait until tomorrow.