Managing sidebars for Blog and WooCommerce

In the widgets I have Main Sidebar using the Product Categories widget.
I have Blog using the Categories widget for blog posts.

The main blog page loads the correct sidebar (Categories).

However if I load a single blog post it loads the Product categories sidebar.

How can I fix this?

Hi,

To fix it, you can try adding the code below in your child theme’s functions.php file.

// =============================================================================
// Assign sidebar to custom post archives
// =============================================================================
add_filter( 'ups_sidebar', 'assign_post_sidebar' );
function assign_post_sidebar($sidebar){
  if (is_singular('post')) {
    return 'ups-sidebar-my-sidebar';
  }
  return $sidebar;
}
// =============================================================================

Don’t forget to replace ups-sidebar-my-sidebar with the actual ID of your custom sidebar as shown below:

Hope that helps

Thank you, that did the trick!

You’re most welcome!

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