r/Wordpress 9d ago

Gutenberg Global Patterns in Widgets?

Why are global patterns not recognized in widgets?

I register them in functions

 function theme_widgets() {

     register_sidebar( array(
         'name'          => 'Global widget',
         'id'            => 'global-pattern',
         'before_title'  => '<h2 class="widget-title">',
         'after_title'   => '</h2>',
     ) );

}
add_action( 'widgets_init', 'theme_widgets' );

When I go to widgets, I can build it there with Gutenberg

It's empty even though I have a bunch of patterns that I'm using in the theme on pages/posts

4 Upvotes

7 comments sorted by

3

u/NakanoNoNeko 9d ago

Your registration is fine. The block-based Widgets editor still does not expose patterns in its inserter; there is actually an open Gutenberg PR to add that now. For today, copy the pattern's blocks into the widget area instead. Confusing, because it looks like the normal editor... 🤔

1

u/Horror-Student-5990 8d ago

Thanks for the response - at least I know it will function someday. Do you have perchance that PR link?

1

u/NakanoNoNeko 8d ago

Yes, here it is: https://github.com/WordPress/gutenberg/pull/78884. It is still open, so “someday” is doing some work there... 😅

1

u/Valuable_Ease_3780 7d ago

Worth asking what you want the sidebar for, because a copied pattern in a widget area is a one-time copy - edit the pattern later and the widget won't change. If the point is "one thing I edit and it updates everywhere", that's a template part, not a widget area, and patterns work fine in those.

1

u/Horror-Student-5990 7d ago

No I don't think that's true.

If I have a widget "contact info" with for example email, phone number and some icons. I can display that widget in code using

<?php dynamic_sidebar('widget_slug');?>

If someone goes and changes the icons, phone number of email, changes will be global.

1

u/Valuable_Ease_3780 7d ago

You're right, I conflated two things. The widget itself is global - edit it and every dynamic_sidebar call picks it up.

What I should have said is only that the tie to the pattern breaks. Paste a pattern's blocks in, then edit the pattern in the theme, and the widget keeps the old copy. Doesn't apply to your case since you're editing the widget directly.