Sidebar dynamic content

Hi, before the introduction of “Layouts” in PRO I could choose if a page has a sidebar or not, and if it has one, I could decide what content appears in it using the “Sidebars” conditions ( * All Pages and Posts, * All Taxonomies, * Post Types) and I had created different sidebars for different pages.

All was fine.

But now with “layouts” when I create a “sidebar” inside a layout I can only assign a specific sidebar.

The problem is this: I don’t want to create a layout for every different sidebar when everything else is the same.

Concrete example: woocommerce category pages.

I want ONE layout (so that I can make changes that get applied globally to every category pages) and different sidebars.
At the moment, as I was saying, it appears I can’t set “Here’s the sidebar, get content from the old Sidebars and old conditions”

All I can see is that I should create different layouts (one for every category page) and when one month from now I will think about making a change I will have to open every layout and change manually every little change.

It’s a problem only because it would get very hard to manage dozens of layouts (btw I can’t even read layouts’ names clearly because they get cut off after 3 or 4 words)

Can anyone confirm that I got it right? Or am I getting it all wrong?

Thank you for your time

Hi @dragend,

Thanks for reaching out about this. You are correct, the Layout Builder doesn’t have awareness of the old sidebar feature and won’t be able to pull through the sidebar from the assigned context. However, in most cases you don’t have to create multiple layouts if you use Element Conditions. You can add multiple Widget Area elements in the Layout and use Element Conditions (Customize Tab) to determine under what criteria it will show.

WooCommerce category pages would require a different layout, but only because the Layout builder has a special WC Archive type used for WooCommerce instead of the standard Archive type.

Thank you for your clear response.

I was aware of the possibility, as you suggested, that I could create ONE layout and add multiple Widget Area but my question is this: Would it get slow/problematic to add 30 conditions and 30 Widget area in one layout?

I mean: will the code have to verify each condition each time before rendering the page so that it will inevitably slow down the page? (it’s a lot of content and a lot of conditions)

What do you think about it, regarding this speed issue?

Hi @dragend,

Sure! I’d be happy to comment on that. So whenever you land on a URL of a WordPress site, WordPress takes that URL and identifies what state should be shown. Some context is built up, like the current post, taxonomies etc. Because WordPress has all the information ready to go, it’s very fast to just ask things like “Are we on the About page?” We can do this hundreds of times without any perceivable performance issues because we are doing very simple comparisons with data that WordPress already brought into memory early on in the page load. When it comes down to it the biggest burden is just the management of it all.

I’m sorry this didn’t come to mind earlier, but I did have one additional thought that may help you. This get’s a bit into custom development which is outside the scope of support we can offer. But, if you’re comfortable with a little custom code and can handle some of the limitations, this might be a better option for you.

Try adding this PHP in functions.php of a child theme:

add_shortcode('x_custom_sidebar', function($content, $atts) {
  ob_start();
  dynamic_sidebar( apply_filters( 'ups_sidebar', 'sidebar-main' ) );
  return ob_get_clean();
});

Now you can place [x_custom_sidebar] somewhere in your Layout like a Raw Content or Text element. You won’t get the wrapping classes of the widget area element and you won’t be able to add things like ID, class, etc. but you it will populate from your site’s main sidebar and allow that to be overridden by any custom sidebars you have setup.

This is probably closer to what you were looking for originally.

Thank you very much!

Great support!

Hi @dragend,

You’re welcome and it’s our pleasure to help you. If you have any other concerns regarding our theme features, feel free to reach us.

Thank you.

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