When you call register_post_type() to register your custom post type, one of the args is called template which is described as follows:
Array of blocks to use as the default initial state for an editor session. Each item should be an array containing block name and optional attributes.
So whereever you have the register_post_type(), you could do:
register_post_type(
'document',
array(
…,
'template' => array(
array(
'core/pattern',
array(
'slug' => 'theme-name/document-block-pattern',
),
),
),
)
);
Or if you want to add the template in some package that is decoupled from the code that calls register_post_type(), you can use the register_{$post_type}_post_type_args hook:
function function_name( $args ) {
$args['template'] = array(
array(
'core/pattern',
array(
'slug' => 'theme-name/document-block-pattern',
),
),
);
return $args;
}
add_filter( 'register_document_post_type_args', 'function_name' );
Related Posts:
- How to enable REST API on custom post type without Gutenberg?
- How to Customize the Admin Sidebar Menu in WordPress Multisite Network by changing the backend code of the wp-admin code files?
- How to get the post title inside a custom block in a loop? block.js
- Running WP Cron on multisite the right way
- Call to a member function add_rewrite_tag() on null
- How to check if image is already stored in a site’s post database? (network)
- Removing Default Gutenberg Blocks, But Keeping Reusable Block Functionality?
- is_admin returning false in backend in server side rendered block
- Customize default settings on new sites on multisite
- Sorting list of sites from multisite network using wp_get_sites
- Integrating WordPress to my website, while keeping my own authentication system
- Remove/unset options field from backend Settings->General?
- Multisite get_home_url(); – Getting URL for current site
- How to use wp_insert_user on WordPress Multisite?
- Sort posts from multiple sites by date
- Gutenberg custom block using only register_block_type() and HTML
- WordPress (3.9.1) MultiSite Permissions. Is chown the answer?
- Register JS for block on frontend only
- How to add values to media “whitelist_options” in wp-admin/options.php template?
- How to programmatically add Gallery Block to Existing Post Content
- Best way to add more options to Gutenberg “More Rich” text controls drop down
- Fetch post block/field data as JSON with WordPress API
- Where to find documentation for CPT block template? (PHP)
- WordPress returning 404 for multisite pages
- How to call plugin function per site in a multisite?
- WordPress returns “The link you followed has expired” error page whenever I add a new site, add a user etc
- Make a list of sites for each user in WPMU – switch_to_blog (display in SITE_ID: 1)
- Moving code from theme header to functions.php
- Count posts on multisite with blog id
- How do I display offsite database info on my wordpress site?
- Timthumb.php image gallery not working on Multisite WordPress
- How to keep the capability of users and disable Gutenberg editor in WordPress?
- Passing the name of selected color from the custom component to `render_callback`
- Find Site ID From WP_Post
- List all blogs, but exclude the main site
- InnerBlocks with allowedBlocks not working with acf_register_block
- Known Issues in WordPress When Upgrading PHP to ver 7
- WordPress homepage setup not working on first load
- Is it legal to redefine wp_password_change_notification in a mu plugin?
- need help adding a new sidebar to a page that can’t use page-templates -> multisite
- WordPress – Get Posts with Category data
- WordPress Multisite login_redirect to primary blog and specific page based on role
- How to populate a Gutenberg select field SelectControl with option value from PHP array
- How can I update WordPress plugins or WordPress itself in all server?
- How to extend SelectControl with data from my theme
- Copying and pasting to WordPress “code editor” code via the front end and clipboard
- Gutenberg block don’t save rich text content
- Is there a PHP function that will return the block ID generated by WordPress?
- register_block_type is not working properly
- Internal Server Errors – Moving working multi-site install to my localhost
- Categories does not show Block editor WordPress
- Annoying/confusing WordPress memory limit exhausted
- Create form which redirects to site in network?
- Redirect user role to a specific page on login in a multisite network?
- Multiple WordPress sites with different theme and plugin sharing the same content
- Changable favicon
- Add .php to end of all WordPress Pages (multisite)
- Adding users to another blog
- Transfer WordPress Login Session to an Extended Webpage on the Same Domain
- Resource 404 error on multisite subdirectory install
- Importing demo data in Multisite
- Display a query with multiple post types and same relationship on a single page
- WP multisite network plugin fails to see classes loaded with spl autoload
- Host does not allow remote connection, so how do I transfer data to my WordPress site?
- Custom PHP-coding in MU installs
- .htaccess on multisite and roots theme?
- I need a button to appear when not loged in and another when logged in, I need help fixing code PLEASE!
- WPMU – How to echo only one URL
- Gutenberg – render_callback does not pass ToggleControl value on frontend
- How can I get values from a custom post type depending on where I click on my SVG map?
- Add default block css when the block has been added with php?
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- Custom Post Type doesn’t have template content when creating programmatically in PHP but does when created in WP Admin
- How to add different menu items on different menus?
- Can I associate a custom post type with another custom post type?
- How to use multiple custom post types to archive as front page?
- add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico
- WordPress taxonomy and terms question
- Load style and script for custom post type metabox
- Custom CPT – Programmatically create categories to assign CPT when a new one is created
- How do I exclude the current post from the upcoming post query
- Custom Filtering date with newsletter
- WordPress Block Editor Gutenberg running code inside ! is_admin()
- How to create a build for quickly deploying a server with WP?
- Custom post type removing /page/2/ from URL when trying to access it
- WordPress CPT & Custom Taxonomy with the SAME Permalink Structure
- Registering a custom block style
- NGINX rewrite rules for WordPress Subdirectory Multisite to support deep URL
- Hot to show custom post type taxonomies on archive page
- child category under correct parent
- Get column block count using PHP method render_block
- do_blocks not working with a custom block
- Redirect WordPress page to the latest created post by the logged in author/user
- create custom post type and populate custom fields using php
- Want to add custom post type for facebook feed
- How to edit templates created in the block editor in code / template files not updating
- Options of select field in a custom divi module ignore sorting
- How to add query string at the end of sitemap Yoast SEO
- When a foreach loop is used multiple times in blocks, is there a way to ensure a variable always has a unique value?
- Custom theme on multisite has issues with standard loop output