Conditional Tags for Portfolio (For Sidebars)

Hi,

Can you please guide us to get Conditional Tags for portfolio post type just like below code that we have done for Blogs and it’s post. We are looking for Conditional Tags for Portfolio Category and Portfolio Tag.

add_filter( 'ups_sidebar', 'assign_sidebars' );
function assign_sidebars($sidebar){
if(is_category() || is_tag()){
  return 'ups-sidebar-blog-sidebar';
}
return $sidebar;
}

Hoping for the solution.
Thank You,
Bibhash Karn

Hello Bibhash,

Thanks for writing in!
You can add x_is_portfolio_category() and x_is_portfolio_tag() in your condition. Therefore, the final code may look like this:

add_filter( 'ups_sidebar', 'assign_sidebars' );
function assign_sidebars($sidebar){
	if( is_category() || is_tag() || x_is_portfolio_category() || x_is_portfolio_tag() ){
	  return 'ups-sidebar-blog-sidebar';
	}
	return $sidebar;
}

The code above serves as an example code. Feel free to modify it when needed. Be advised that this is beyond the scope of our support under our Support Policy. You will have to maintain any custom coding to make sure that it will still work after any updates or does not create any issues or incompatibility in the future. If you are unfamiliar with code and resolving potential conflicts, you may select our One service for further assistance.

Best Regards.

Hi,

Thank you for your response.

Actually we wanted different sidebar for Portfolio and it’s category and tags. So we used below code and it worked perfectly.

add_filter( 'ups_sidebar', 'assign_sidebars' );
function assign_sidebars($sidebar){
if(is_category() || is_tag()){
  return 'ups-sidebar-blog-sidebar';
}
else if(x_is_portfolio_category() || x_is_portfolio_tag()){
  return 'ups-sidebar-portfolio-testimonial-sidebar';
}
return $sidebar;
}

Thank you for your help.

You are most welcome, Bibhash.

1 Like