Conversation
supportHello, I would like to have different sidebars for my Woocommerce category. How can I assign them to each category? Thanks in advance!
Hello, Please create a new sidebar using the ocean custom sidebar plugin and add the widgets as per your need. Add the below code in the functions.php file of your child theme. function prefix_cpt_sidebar( $sidebar = 'sidebar' ) { if ( is_category( 'YOUR CATEGORY NAME HERE' ) ) { $sidebar = 'your-sidebar-id'; } return $sidebar; } add_filter( 'ocean_get_sidebar', 'prefix_cpt_sidebar' ); PS- Replace the sidebar id with your own and YOUR CATEGORY NAME HERE. You can also use conditional tags according to need. https://codex.wordpress.org/Conditional_Tags
Hi Abhishek, The code didn’t work, the default Woocommerce sidebar is still displaying on the category. Here’s the code in case I missed something: function prefix_cpt_sidebar( $sidebar = 'sidebar' ) { if ( is_category( 'red-wine' ) ) { $sidebar = 'ocs-red-wine'; } return $sidebar; } add_filter( 'ocean_get_sidebar', 'prefix_cpt_sidebar' ); Thanks for your help.
Hello, Please try to clear the cache and check. Kindly share the page URL where you are trying this and also share the snapshot of your sidebar settings/name.
Hi again, the site is in development so I don’t have any cache plugin installed yet. Here are the screenshots so you can have a better look: Sidebar: https://www.awesomescreenshot.com/image/10610730?key=239d35ccfb57a9579666b39e9cdff584 Widgets: https://www.awesomescreenshot.com/image/10610922?key=93007ced9373fae6be4b04e2cb94cd96 Category page: https://www.awesomescreenshot.com/image/10611227?key=261b68f325ef8851d69651f6adfef7c3
Hello, Thank you for sharing teh snapshots, Kindly try the below code and check. function prefix_cpt_sidebar( $sidebar = 'sidebar' ) { if ( is_category( 'red-wine' ) ) { $sidebar = 'Red Wine'; } return $sidebar; } add_filter( 'ocean_get_sidebar', 'prefix_cpt_sidebar' ); Also, try to change the name of the category/sidebar and check.
Hi Abhishek, It’s still not working I tried changing the category and sidebar but nothing happens. What else could it be? Thanks again.
Hello, That is odd, if possible open a ticket at the helpdesk. So I can try to take a closer look into the issue.
Hello, Please create a new sidebar using the ocean custom sidebar plugin and add the widgets as per your need. Add the below code in the functions.php file of your child theme. function prefix_cpt_sidebar( $sidebar = 'sidebar' ) { if ( is_category( 'YOUR CATEGORY NAME HERE' ) ) { $sidebar = 'your-sidebar-id'; } return $sidebar; } add_filter( 'ocean_get_sidebar', 'prefix_cpt_sidebar' ); PS- Replace the sidebar id with your own and YOUR CATEGORY NAME HERE. You can also use conditional tags according to need. https://codex.wordpress.org/Conditional_Tags
Hi Abhishek, The code didn’t work, the default Woocommerce sidebar is still displaying on the category. Here’s the code in case I missed something: function prefix_cpt_sidebar( $sidebar = 'sidebar' ) { if ( is_category( 'red-wine' ) ) { $sidebar = 'ocs-red-wine'; } return $sidebar; } add_filter( 'ocean_get_sidebar', 'prefix_cpt_sidebar' ); Thanks for your help.
Hello, Please try to clear the cache and check. Kindly share the page URL where you are trying this and also share the snapshot of your sidebar settings/name.
Hi again, the site is in development so I don’t have any cache plugin installed yet. Here are the screenshots so you can have a better look: Sidebar: https://www.awesomescreenshot.com/image/10610730?key=239d35ccfb57a9579666b39e9cdff584 Widgets: https://www.awesomescreenshot.com/image/10610922?key=93007ced9373fae6be4b04e2cb94cd96 Category page: https://www.awesomescreenshot.com/image/10611227?key=261b68f325ef8851d69651f6adfef7c3
Hello, Thank you for sharing teh snapshots, Kindly try the below code and check. function prefix_cpt_sidebar( $sidebar = 'sidebar' ) { if ( is_category( 'red-wine' ) ) { $sidebar = 'Red Wine'; } return $sidebar; } add_filter( 'ocean_get_sidebar', 'prefix_cpt_sidebar' ); Also, try to change the name of the category/sidebar and check.
Hi Abhishek, It’s still not working I tried changing the category and sidebar but nothing happens. What else could it be? Thanks again.
Hello, That is odd, if possible open a ticket at the helpdesk. So I can try to take a closer look into the issue.