customization – Restrict block patterns and template for page template


I’m facing two problems with Gutemberg to be able to use it correctly, maybe some of you have an idea how to solve them ?

I know how to create a custom template for all pages :

$page_post_type = get_post_type_object('page');
    $page_post_type->template = [
        ['core/cover', ['align' => 'full', 'overlayColor' => 'blue-profile'], [
            ['core/heading', ['align' => 'center', 'placeholder' => __('Call to action title', 'txtdomain')]],
            ['core/paragraph', ['align' => 'center', 'placeholder' => __('Your text here', 'txtdomain')]],
            ['core/button', ['align' => 'center']]
    $page_post_type->template_lock = 'all';

  1. But is there a way to do it for a custom page template ?

Then, I use in my plugin the following method to restrict block types :

add_filter('allowed_block_types', array($this, 'restrict_blocks'), 10, 2);
  1. Is there a way to also restrict block patterns that I created or only classic blocks ?
    (I know how to disable all of them, disable specific category for all, but ‘allowed_block_types’ allow me to show some blocks for some post types and not for others, exactly what I’m looking for with block patterns)

Thanks a lot in advance!

Olivier 2 months 2021-04-13T02:41:34-05:00 0 Answers 0 views 0

Leave an answer