Skip Navigation

[Resolved] Gutenburg patterns as default template

This support ticket is created 3 years, 12 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by Jamal 3 years, 12 months ago.

Assisted by: Jamal.

Author
Posts
#1892267

I made a custom post type called STAFF with toolset and I made a gutenburg pattern. I'd like this pattern to show up everytime I create a new staff post. This code works below for reusable patterns and core individual blocks but I don't know how to get a pattern to show up in there.

//add default blocks to post type
function myplugin_register_template() {
$post_type_object = get_post_type_object( 'staff' );
$post_type_object->template = array(
array( 'core/paragraph' , array('placeholder' => 'Type Information about this staff member',) ),
array( 'core/block', array('ref' => 436,// Reusable block id),
),
);
}
add_action( 'init', 'myplugin_register_template' );

#1893155

Hello and thank you for contacting the Toolset support.

What you can do, is create a content template and assign it to your custom post type. Then add the pattern to this content template. Each new post will get this content template assigned. Read more about it on our glossary page:
- https://toolset.com/glossary/template/

Check our documentation for more tutorials: https://toolset.com/course-lesson/?wpv-related-lesson=post-templates&wpv_view_count=1599013

I hope this helps. Let me know if you have any questions.

#1893293

Thanks for the reply. Unfortunately that doesn't help with what I am asking in this situation. To be clear, I'm not asking to show the pattern when someone views a staff profile on the frontend. I'm asking how to load a certain chosen pattern by default into gutenburg when someone adds a new staff post. Then they can start editing that pattern if they want right there in gutenburg. Assigning a content template doesn't help with that, which is why I provided the code that is normally used (hoping you can help know how to add a pattern).

Hope that helps clarify! Thanks for help!

#1894109

Thank you for the explanation. I understand now that you want the pattern to automatically go into a new post content(or body).

First of all, note that a pattern, a block or anything inside the block editor is HTML that includes comments used by the block editor, such as(wp:paragraph):

<!-- wp:paragraph -->
<p>Content Area #1</p>
<!-- /wp:paragraph -->

You need to create a new post, add the pattern to it and switch to code editor in order to copy the HTML markup of the pattern. You will use it later.

If you are creating new posts from the backend, check the following article, it explains how to add default content to a post using custom code, especially the default_content hook.
hidden link

If you are creating new posts from the frontend using Toolset Form, you can use the cred_save_data hook.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data