Sidebar question

I want to have a custom “shop” sidebar that appears on ALL shop pages, including category archives (ex. if someone clicks on a category and it takes them to a new shop page with products in that category).

I want a custom “blog” sidebar to appear on ALL blog pages - the main one and the individual post pages.

Do I literally have to assign those sidebars to each and every category to make that happen? Some of my blog post categories have the same name as some of the products (ex. “dog behavior”). So if I have to do this, I will first have to go and change some category names. I would think there would be some kind of global command to assign a sidebar to the shop and all associated pages, and another one to the blog and all associated pages.

What I’m experiencing is that the correct sidebars do appear on the main shop page and main blog page. But the sidebar called “main sidebar” is the one that shows up on each and every other page. I tried to delete that sidebar but apparently you can’t do that?

Sorry for such a dumb question but I’m wasting so much time. :confused:

Hi @creatorofstuff

I believe that if you created a new sidebar with these options enabled:

You will get that sidebar appearing on (main Shop page, product categories pages, product single pages) which I believe is what you are seeking for.

For more information, please check this guide for more information:

Thanks.

Thanks for your reply.

I’ve read the article, and had already created two new sidebars. One for the blog (and all blog pages), and one for the shop (and all associated pages). I have a ton of taxonomies, but none of them show as “shop_cat” or “post_cat”. I had also selected the two options you specified.

As it stands, the sidebars only show up on the main shop page and the main blog page. Every other page for each shows that “main sidebar”.

There must be a way for this to work. I can’t imagine having to assign a sidebar every time you add a new category to either posts or products.

In the meantime, my site is in maintenance mode until I can get this resolved, so I’d like to figure it out.

I’m going to add a private note with login credentials so you can see what’s going on, if you don’t mind. Thank you!

I should clarify concerning the blog sidebar. It works on the main blog page and individual blog posts. It doesn’t work when you select a post category. Then you see that pesky “main sidebar”. Sorry for any confusion about that.

Hi, Creator of Stuff! :slight_smile:

To be able to add a sidebar to batch pages and categories you need to follow the steps below:

1- Install a Child Theme.
2- Go to Appearance > Sidebars and add a sidebar for the shop and another one for the blog.
3- Copy the ID of the sidebar in question which you will use later:

4- Go to Appearance > Widgets and assign necessary widgets to the sidebars in question.
5- Go to the functions.php file of your Child Theme and add the code below:

add_filter( 'ups_sidebar', 'assign_sidebars' );

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

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

##In this case:
ups-sidebar-the-shop-sidebar: is the ID of the shop sidebar I added.
ups-sidebar-the-blog-sidebar: is the ID of the blog sidebar I added.
is_woocommerce() is the conditional tag which I used to determine the page is woocommerce generated or not which leads to all shop pages including the categories and stuff.
is_category() is the conditional tag I used to determine a page is a category page.

For more information about the Woocommerce Conditional Tags click here.

For more information about the WordPress Conditional Tags check below:

https://codex.wordpress.org/Conditional_Tags#A_Category_Page

Thank you.

That is fantastic! It’s exactly what I was seeking, and it works. Thank you so much! :grin:

You’re welcome!
Thanks for letting us know that it has worked for you.

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