How to conditionally register/unregister patterns #296
Replies: 2 comments
-
This topic was approved in the 9/5 editorial group meeting. Please continue the conversation on the issue |
Beta Was this translation helpful? Give feedback.
0 replies
-
Published: Snippet: Conditionally unregister patterns |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When building a theme, I am sometimes building patterns that rely on a third-party block. In general, this works well enough with WordPress, giving a notice to the user that they need to install and activate the block.
However, not all theme authors want those patterns to appear without the block installed.
It's easy enough to only register patterns with a late
init
action and a conditional check. However, themers lose the ability to use the auto-registration via the/patterns
folder.Instead, we can conditionally unregister these without losing
/patterns
folder support. This would be a short tutorial with a reasonably small bit of code to explain the technique.A code example is here: https://github.com/x3p0-dev/x3p0-ideas/blob/869d801bd7e11dccffb4b344b174c7b52ac89e52/src/Patterns.php#L134-L152
I'm not 100% sure this is worthy of a full tutorial, but not everything needs to be epic either. Sometimes these small techniques can be very helpful. This should definitely be sub-1,000 words.
Beta Was this translation helpful? Give feedback.
All reactions