Sidebar problem only on new posts

Hi. I had asked a question in this thread:


which you answered beautifully. The solution given at the end worked. However, it doesn’t work for new posts. Can you help me fix it?

I have two sidebars. One, I want to appear on all shop pages, and all shop category pages. The second, I want to appear on the main blog page and all individual blog posts.

The latest post shows the “shop” sidebar instead of the “blog” sidebar.
https://sassypantsdesign.com/tighty-whitey-underwear-adventure-a-true-story/

Here is the code I am using. Thanks!

add_filter( ‘ups_sidebar’, ‘assign_sidebars’ );

function assign_sidebars($sidebar){
if(is_woocommerce()){
return ‘ups-sidebar-shop-sidebar’;
}

if (is_category()) {
	return 'ups-sidebar-blog-sidebar';	
}
return $sidebar;

}

Hi,

The url you provided is a post and there is no sidebar assigned for post.

Please change your code to this.

add_filter( 'ups_sidebar', 'assign_sidebars' );

function assign_sidebars($sidebar){
if(is_woocommerce()){
    return 'ups-sidebar-shop-sidebar';
}

if (is_category() || is_singular('post')) {
	return 'ups-sidebar-blog-sidebar';	
}
return $sidebar;
}

Please note that I added is_singular('post') in the conditional statement

By adding that, it will assign ups-sidebar-blog-sidebar to all your post.

Hope this helps

Thank you! That worked great. I don’t understand why all of the other posts were already working, but I’m happy. This did the trick. :grin:

You’re most welcome!

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