Custom Sidebar on All Blog Posts/Index

I spent 20 mins searching through the threads and could not find this solution anywhere…

We use the default sidebar for WooCommerce pages and created a custom sidebar for Blog posts. However I cannot figure out how to get the custom sidebar (ups-sidebar-blog-sidebar) to show on all blog posts…only shows on the index. You would think checking “Enable parent page sidebar on child pages” would make it apply to the posts, but that checkbox seems to serve no function in this case.

I know of one way to make it appear and that is to check off every blog post in the sidebar settings, but as you can understand this is asinine and non-intuitive. For sites where bloggers have different permissions, it’s a non-starter as an admin would have to remember to go in every time and check the box for every new blog post. It’s just not feasible.

So how do we do it? How can we automatically assign the custom sidebar to the blog index and all blog posts? Thanks.

Hi There,

Thank you for writing in, while that is outside the scope of support, I could point you in the right direction with the understanding that it would ultimately be your responsibility to take it from here.

First, please set up a child theme, then add the following code on your child theme’s functions.php file.

/* assign custom sidebar to single posts */
add_filter( 'ups_sidebar', 'add_custom_sidebar' );
function add_custom_sidebar($sidebar){
  if(is_singular( 'post' )){
    return 'SIDEBAR ID HERE';
  }
  return $sidebar;
}

Change the SIDEBAR ID HERE with the actual ID of your sidebar.

Hope it helps,
Cheers!

1 Like

I’m not quite sure I’d call that outside the scope of support…I prefer to call it “assistance to make up for a gap in Pro’s expected functionality”. Most of the Top 10 premium WP themes easily allow you to assign a specific sidebar to blog posts, so I don’t consider this request unusual or out of scope.

Your custom function worked perfectly. Thank you.