Hi there,
I´d like to show custom sidebars for certain category pages.
I found a good start here:
/* assign custom sidebar to single posts within certain categories */
add_filter( ‘ups_sidebar’, ‘add_custom_sidebar’ );
function add_custom_sidebar($sidebar){
if ( is_singular(‘post’) && in_category( array( 6,10 ) )) {
return 'ups-sidebar-XXXXXXX;
}
return $sidebar;
}
To show different sidebars for other categories, how to adapt that function above?
Hello @Mbzo,
Thanks for asking. 
If you are looking to add custom sidebar sidebar for category pages, you can do this without custom code. All that needs to be done is create sidebar under Appearance > Sidebar and under All Taxonomies select the categories. After that from Appearance > Widgets add widgets in the sidebar you have just created.
To help you get started, I have recorded a screencast. Please take a look. https://cloudup.com/c_fto5cL2oI
If you are looking for something else, please clarify and we will be happy to help you out.
Thanks.
Hi @Prasant, thanks for that.
Yes, that’s the solution I tried first. However, the sidebars were simply not working for child pages (a bug?)
Even if I check several taxonomies, only the top-level taxonomy page seems to show the sidebar.
So, this solution seems to work for individual posts (or pages) but does not work for child categories. The desired custom sidebar only appears on the parent category page.
Hello @Mbzo,
Thanks for updating the thread. 
Please add following code in your child theme function.php file:
add_filter( 'ups_sidebar', 'custom_sidebar_on_pages', 9999 );
function custom_sidebar_on_pages ( $default_sidebar ) {
if ( in_category('Audio') ) {
return 'ups-sidebar-custom-sidebar';
}
elseif ( in_category('Video') ) {
return 'ups-sidebar-news-events';
}
return $default_sidebar;
}
In above code you need to replace Audio, Video with category name and ups-sidebar-custom-sidebar and ups-sidebar-news-events with custom sidebar id’s in case you want to display separate sidebar for other categories. In case you want to display same sidebar then just replace with same sidebar id.
In above code I have used a conditional tag in_category. If you would like to learn more about conditional tags, please take a look at following resources.
https://developer.wordpress.org/reference/functions/in_category/
https://developer.wordpress.org/themes/basics/conditional-tags/
Thanks.
You are most welcome. 
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.