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
- 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)
- How to serialize a Gutenberg block from block attributes in PHP?
- Removing Default Gutenberg Blocks, But Keeping Reusable Block Functionality?
- How does wordpress know which site to setup (on multisite)?
- Gutenberg Blocks doesn’t render correctly when using do_blocks
- add_meta_boxes action with refresh on save
- Network installation giving errors when viewing or adding a user
- Fix 403 error on WordPress multisite network using subdomains
- Include a Gutenberg Block in a PHP file
- How to create Sub Sub domain Multi User blogs?
- Create custom blocks for bootstrap
- Why am I getting ERR_NAME_NOT_RESOLVED when I add a site to my multisite installation? [closed]
- How to return output of the new wp gallery block for automatically Link images To Media file
- How to add custom taxonomy slug in CPT permalink?
- Custom php page outside the scope of my theme
- Adding hreflang tags automatically in WordPress subdirectory multisite
- How to change home or site url using action hooks or filter?
- Displaying admin notices inside the block editor from rest_after_insert_{$this->post_type} hook
- Best way to add more options to Gutenberg “More Rich” text controls drop down
- wordpress media library new uploads don’t write to database
- Fetch post block/field data as JSON with WordPress API
- Where to find documentation for CPT block template? (PHP)
- Generate YouTube image thumbnail in a Gutenberg block – ACF + Timber
- How to call plugin function per site in a multisite?
- NGINX rewrite rules for multisite
- wp_redirect only works on main site and not on other sites
- Timthumb.php image gallery not working on Multisite WordPress
- parsing nested blocks (in columns, etc) via PHP
- 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
- Guttenburg and Classic Editor – How to use the custom guttenburg block in classic editor?
- How to render a block from php template
- How to disable all logins except Network login in WordPress Multi site?
- Is it legal to redefine wp_password_change_notification in a mu plugin?
- Authentication from sub-folder non-wp cookie WordPress
- WordPress: Displaying all the post tags from within a specific taxonomy’s term
- Want to unrestrict plugin block
- WordPress – Get Posts with Category data
- How to Redirect Buddypress Directories To Login Page For Non Logged in Users
- Add Block Before Entry Title Using PHP
- Gutenberg Blocks and get_option() for styling
- Gutenberg block don’t save rich text content
- Is there a PHP function that will return the block ID generated by WordPress?
- Merging Multiple WordPress Websites
- Create form which redirects to site in network?
- Multiple WordPress sites with different theme and plugin sharing the same content
- PHP script to redirect traffic based on website accessed
- Transfer WordPress Login Session to an Extended Webpage on the Same Domain
- Resource 404 error on multisite subdirectory install
- Relationship between custom post type and page/single templates
- WP Admin Bar – Get current theme name as custom menu title
- 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?
- Trying to post information from a remote database to wordpress page
- Force string into signup form
- Losing Session ID and sessionStorage when navigating to other domains on Multisite
- Display all categories (with link) of custom post type – WordPress
- Displaying custom meta box value in a custom post page
- WordPress different custom tag being displayed in on tag list
- Get category name of current post (CPT UI)
- How to sort custom sortable column by custom table value
- I want to show image from custom field image on my custom page template
- How to disable page create for custom post type, but allow a page with the post types slug to be created?
- Replace block content with an array
- Include a static block inside of a dynamic block
- How to make multiple custom taxonomies sit under custom post type slug?
- Limit a search box by CPT + taxonomies, in only one page
- add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico
- Load style and script for custom post type metabox
- Internal server error when enabling Multisite in WordPress
- Why do I get a 404 error on my custom post type archive pagination?
- Save_Post change Custom Post Type Post title to post id number
- Ajax infinite scroll random order shows duplicate posts on custom post type
- WordPress Block Editor Gutenberg running code inside ! is_admin()
- How to create a build for quickly deploying a server with WP?
- Manipulating the allowed inner blocks of a core-gutenberg-block?
- Same Custom Post Type Slug and Custom Taxonomy Slug, with hierarchial unique permalink structure
- fetch from an external api call and display results in page
- Adding features to Gutenberg without theme.json
- Remove slug and custom post type name from URL
- Integrate a Custom Post Type with Learndash Plugin
- Single wordpress multi website down need help factoring what it is
- Remove slug of multiple custom post types with and without hierarchical
- Quiz page template, checked attribute missing when option selected
- ACF block gutenberg aligncenter don’t work
- Is it possible to go to the next post in the same category?
- create custom post type and populate custom fields using php
- Want to add custom post type for facebook feed
- Running WP-Cron on Multisite networks the right way?
- 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?
- Prevent render in editor via PHP
- How to Bulk Update CPT Taxonomy Values Using CSV Lookup Table
- How to get the content of a dynamic block in PHP