With the Block Editor (also known as Gutenberg), all post types that have support for default templates for which order your block will show up when you create a new post. For events, we introduced a filter to allow you to customize your default content easily.
- Hook name:
tribe_events_editor_default_template - Parameters used on this Filter
$template– Array with Template blocks to be generated$post_type– String with the Post type we are dealing with. Defaults totribe_events.$args– Array of arguments used to set up the Templates
We have a list of default blocks loaded by The Events Calendar. In the following order:
tribe/event-datetimecore/paragraphtribe/event-pricetribe/event-organizertribe/event-venuetribe/event-websitetribe/event-links
Here are a few examples of how you would use this, such as removing the Price block or changing the whole template.
Remove the Price block
<?php
add_filter( 'tribe_events_editor_default_template', function( $template ) {
// collect an array of template values, like "tribe/event-price" and tribe/event-venue"
$template_search = array_column( $template, 0 );
// Get the index of the "tribe/event-price"
$price = array_search( "tribe/event-price", $template_search );
// @link: https://www.php.net/manual/en/function.array-splice.php
array_splice(
// The original $template array
$template,
// The integer value of the price index (such as 2)
$price,
// How many items we want to remove from $template (just 1: the price)
1
);
// Return the price-spliced $template
return $template;
}, 11, 1 );
Change the template
<?php
add_filter( 'tribe_events_editor_default_template', function( $template ) {
$template = [
[ 'tribe/event-datetime' ],
[ 'core/paragraph', [
'placeholder' => __( 'Add Description...', 'the-events-calendar' ),
], ],
[ 'tribe/event-organizer' ],
[ 'tribe/event-venue' ],
];
return $template;
}, 11, 1 );
It’s important to remember that the default value for each one of the blocks is an array that has the first key (0) as the block slug.
Adding more WordPress core blocks when changing the template
Note that the previous PHP snippet includes the default paragraph block from WordPress, so you can also include other WordPress default blocks if you need to.
As an example, if you need to include the Featured Image block, you’ll need to include the ['core/post-featured-image'] on the position you want to appear.
Let’s see how you can add it before the paragraph block:
<?php
add_filter( 'tribe_events_editor_default_template', function( $template ) {
$template = [
[ 'tribe/event-datetime' ],
[ 'core/post-featured-image' ],
[ 'core/paragraph', [
'placeholder' => __( 'Add Description...', 'the-events-calendar' ),
], ],
[ 'tribe/event-organizer' ],
[ 'tribe/event-venue' ],
];
return $template;
}, 11, 1 );
You can find a list of all default WordPress blocks at https://developer.wordpress.org/block-editor/reference-guides/core-blocks/ and use their “Name” to include them on that list.
Remove the Related Events Block
The following code snippet assists in removing the Related Events block from the default template,
Remove RSVP, Tickets, and Attendees Block
The following code snippet removes the RSVP, Tickets, and Attendees blocks added by the Event Tickets plugin,