Automatically Assign all New Posts a "Sidebar B"

I’d like to assign all new posts, and all posts previous posts to automatically use a custom sidebar, “Sidebar B”

My pages, I would like to use the main sidebar.

I tried a few ways to do this, but I’m not having luck and I feel like I’m not getting something about how this should work.

For now I’ve manually assigned the sidebar to all the posts I have, but we don’t want to have to do that every time we post. What should we do?

Hi David,

Thanks for reaching out.

Are you referring to the creared sidebar in Admin > Appearance > Sidebars? Or is it sidebar custom layout (template related)?

If it’s about the sidebar created in Admin, then please add this code to your child theme’s functions.php with the sidebar ID.

function assign_custom_sidebar($sidebar){
  if ( is_singular('post') ){
    return 'ups-sidebar-sample';
  }
  return $sidebar;
}
add_filter( 'ups_sidebar', 'assign_custom_sidebar');

Cheers!

thank you! exactly what I need. awesome!

You are most welcome!

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