Archived topic
Woocommerce sidebar shop page
7 replies · Started by Robert on October 21, 2017
I'd like to add a custom sidebar to just the Woocommerce shop page. I created a new sidebar and tried to get it to show up on the woocommerce default shop page but alas, nothing. Any ideas? The sidebar is showing up under Widgets.
add_action( 'widgets_init', 'theme_slug_widgets_init' );
function theme_slug_widgets_init() {
register_sidebar( array(
'name' => __( 'woo', 'woo' ),
'id' => 'woo',
'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'woo' ),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
) );
}
add_action( 'wp','tu_woocommerce_sidebar' );
function tu_woocommerce_sidebar()
{
if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
remove_action( 'generate_sidebars','generate_construct_sidebars' );
add_action( 'generate_sidebars','tu_construct_woocommerce_sidebar' );
}
}
function tu_construct_woocommerce_sidebar() {
get_sidebar( 'woo' );
}
Hi there,
So I assume you are using sidebar already on other pages as well?
This plugin might be the easiest: https://en-ca.wordpress.org/plugins/content-aware-sidebars/
Nope, I haven't used this sidebar on any pages, I created it specifically for this one page.
Ahh if that's the case, set the global setting to Content (No Sidebar): https://docs.generatepress.com/article/sidebar-layout/
Then turn it on for WooCommerce only: https://docs.generatepress.com/article/woocommerce-overview/#shop
Let me know.
Sorry, maybe I wasn't clear. I am using sidebars throughout the site, but I would like to create a brand new one, specifically used for just the Woocommerce pages, and not use an existing one. I registered the new sidebar, the issue is having it show up only on the Woocommerce pages, as the default sidebar is currently showing.
Have you tried this plugin? https://en-ca.wordpress.org/plugins/content-aware-sidebars/
I haven't. I was trying to avoid having to use a plugin and managing multiple widgets. I find it cleaner to do it by just creating a new sidebar and assigning it to a page but I guess that isn't possible with this theme. Thanks.
No problem!