• Resolved Shacy

    (@shacy)


    I want to insert created pattern in theme header thru php code. How can i achive this?

    Maybe shortcode functionality might be interesting for users?

    • This topic was modified 1 year ago by Shacy.
Viewing 1 replies (of 1 total)
  • Plugin Author BlockMeister

    (@blockmeister)

    I will add the shortcode to the feature request list.
    It is maybe something we could add in a future release (I am not sure yet though).

    What you are after is actually something that also applies when building patterns with the pattern editor that now comes with WordPress.

    So maybe you could ask for help on the ‘Developing with WordPress Forum‘.

    But to get you started you could try using the WP PHP API, try something like this in your header template:

    $registry = \WP_Block_Patterns_Registry::get_instance();
    $registered_patterns = array_column($registry->get_all_registered(),'content','name');
    $my_pattern_name = 'my-name-space/my-pattern-name';
    $my_pattern = $registered_patterns[$my_pattern_name];
    echo do_blocks( $my_pattern );

    I didn’t test that code but something like that might work. I hope it gets you started ?? Again please ask on the mentioned forum if you need more assistance with this.

    By the way, to find out your namespace and pattern name you could e.g. temporary print $registered_patterns to your screen.

Viewing 1 replies (of 1 total)
  • The topic ‘i it possible to insert pattern in php?’ is closed to new replies.