Taxonomies not showing in Sidebar settings

Hi there. I have cleaned up post categories but they do not show as Taxonomies and I am having to hand select each one I want to show with any given Sidebar. Is that really the way this is intended to act? Can I select the sidebar when I create a new post or do I have to go into the Sidebar settings? Am I missing something?

If the Taxonomies are working will it show up on the appropriate posts? How can I get these to work?

Is this still slated to be finished? I hope so. It is very useful. It seems that for something you tote as a ‘Feature’ it would have better functionality. Thank you.

Hi Georgia,

If you are talking about selecting sidebars created with the method below:

You can not have a mass select, and you need to do it one by one.

There is a custom solution to use the conditional tags to assign a sidebar to series of pages or categories or taxonomies. The implementation of such a feature is outside of our support scope. But we will be able to guide you through so that you can implement the feature yourself.

You will need to install the Child Theme and add a sidebar from Appearance > Sidebar. In the sidebar options you will see the ID of the sidebar:

Write that down. Then add the code below to the functions.php file of your Child Theme:

add_filter( 'ups_sidebar', 'portfolio_sidebar' );
function portfolio_sidebar($sidebar){
	if(x_is_portfolio_item()){
		return 'ups-sidebar-portfolio';
	}

	if (is_tax('test')) {
		return 'ups-sidebar-portfolio';	
	}
	return $sidebar;
}

In the code above, the is_tax is a conditional tag which you can use to select a taxonomy and assign the Sidebar ID that you wrote down before as a return of the function. For more information about the Conditional Tags that you can use, please read the article below:

https://codex.wordpress.org/Conditional_Tags

Thank you.

Thank you. Can I do this for each of the 4 categories?

More questions. Thank you.

I have a category called writing so would it be the following: or similar for each of the 5 categories:

On the page you directed me to it mentions categories done like: is_category( ‘Stinky Cheeses’ ) so I am confused a bit. Thank you!

Hi @GeorgiaG,

Sure, you can do that for your selected categories through code. And I guess you’re confused with already implemented code in your site. They are similar, the only difference is the condition so if you have to use and apply different sidebars then what you need are multiple conditions as well.

Example, this is the main block

add_filter( 'ups_sidebar', 'enforce_my_sidebar' );
function enforce_my_sidebar($sidebar){

/* your conditions and chosen sidebar here */

return $sidebar;
}

Let’s say we wish to display a different sidebar on posts, then resulting code will be

add_filter( 'ups_sidebar', 'enforce_my_sidebar' );
function enforce_my_sidebar($sidebar){

if ( is_singular ('post') ) return 'ups-sidebar-home';

return $sidebar;
}

or different sidebar on blog page

add_filter( 'ups_sidebar', 'enforce_my_sidebar' );
function enforce_my_sidebar($sidebar){

if ( is_home() ) return 'ups-sidebar-home';

return $sidebar;
}

And since it’s the same 'ups-sidebar-home', then we can just combine the two

add_filter( 'ups_sidebar', 'enforce_my_sidebar' );
function enforce_my_sidebar($sidebar){

if ( is_singular ('post') ||  is_home() ) return 'ups-sidebar-home';

return $sidebar;
}

The point is, you don’t need to add the same block of code, what you need is just to modify your existing one and apply your own conditions. Example, let’s add the category

add_filter( 'ups_sidebar', 'enforce_my_sidebar' );
function enforce_my_sidebar($sidebar){

if ( is_singular ('post') ||  is_home() || is_category('news') ) return 'ups-sidebar-home';

if ( is_category('video') || is_tax('portfolio-category', 'video') ) return 'ups-sidebar-video';

if ( is_tax('event-category') ) return 'ups-sidebar-booking';

return $sidebar;
}

In that sample, we’re not displaying two different sidebars for the post, blog, and news category, then another for blog and portfolio video category, and for event taxonomy.

There are many conditions, and only add one according to your preference.

Thanks!

First I need to confirm my expected results: if I mark an article as a specific category then visit the post on the front end it will have the appropriate sidebar for that category without me having preselected it on the backend in the sidebar settings? Is that what should happen? If so, it does not work unless I go and select it in the sidebar settings.

Here is what I entered. - I only have one subcategory and it will share the same sidebar as the parent category. Also the Taxonomies list is blank with just 2 checkboxes an no labels so I am guessing it is the same as the category

// Sidebars
// =============================================================================
add_filter( ‘ups_sidebar’, ‘enforce_my_sidebar’ );
function enforce_my_sidebar($sidebar){
if ( is_category(‘art’) || is_tax(‘art’) ) return ‘ups-sidebar-art’;
if ( is_category(‘art’) || is_tax(‘art-category’, ‘portfolio’) ) return ‘ups-sidebar-art’;
if ( is_category(‘updated’) || is_tax(‘updates’) ) return ‘ups-sidebar-updates-reflections’;
if ( is_category(‘writing’) || is_tax(‘writing’) ) return ‘ups-sidebar-writing’;
return $sidebar;
} */

Hello @GeorgiaG,

Please be advised that is_category() and is_tax() will return TRUE or FALSE if it is a category archive page or a taxonomy page. The sidebars will only display in these pages. If you want to display the sidebars in single blog posts, you may include or add another condition which is has_category and has_term().

Please check this codex:

You condition maybe updated to:

if ( is_category('art') || is_tax('art') || ( is_single() && has_category('art') ) || ( is_single() && has_term('art') )  ) return 'ups-sidebar-art';

Hope this helps.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.