I’ve registered a block pattern in my custom theme (using register_block_pattern) and it’s not displaying in the block patterns list so I’m trying to debug whether I registered it properly.
How could I programmatically find currently registered block patterns?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
This looks like quite new functionality, the docs say ‘experimental’ and the first commit of this code to the WP repo was 6 days ago from date of this writing, so wouldn’t be surprised if you’ll have issues with what you’re doing related to it being in development.
The class that manages block patterns is easy to read:
So you could call e.g. the get_all_registered() method like:
WP_Block_Patterns_Registry::get_instance()->get_all_registered()
or e.g. check if your pattern is registered:
WP_Block_Patterns_Registry::get_instance()->is_registered("your_pattern_name")
I’d suggest if you’re having problems you might either want to wait until it’s a more stable feature or contact the people working on it (e.g. you could start by contacting the person who made that commit as it looks like they’re actively working on it)
HTH!
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0