{"id":1896710,"date":"2019-10-18T13:19:56","date_gmt":"2019-10-18T17:19:56","guid":{"rendered":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/change-the-default-event-template-in-block-editor\/"},"modified":"2024-09-10T04:27:36","modified_gmt":"2024-09-10T08:27:36","slug":"change-the-default-event-template-in-block-editor","status":"publish","type":"post","link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/change-the-default-event-template-in-block-editor\/","title":{"rendered":"Setting Default Blocks in the Block Editor"},"content":{"rendered":"\n<p>With the Block Editor (also known as <em>Gutenberg<\/em>), 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.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Hook name: <code>tribe_events_editor_default_template<\/code><\/li>\n\n\n\n<li>Parameters used on this Filter\n<ul class=\"wp-block-list\">\n<li><code>$template<\/code> &#8211; Array with Template blocks to be generated<\/li>\n\n\n\n<li><code>$post_type<\/code> &#8211; String with the Post type we are dealing with. Defaults to\u00a0<code>tribe_events<\/code>.<\/li>\n\n\n\n<li><code>$args<\/code> &#8211; Array of arguments used to set up the Templates<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>We have a list of default blocks loaded by The Events Calendar. In the following order:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tribe\/event-datetime<\/code><\/li>\n\n\n\n<li><code>core\/paragraph<\/code><\/li>\n\n\n\n<li><code>tribe\/event-price<\/code><\/li>\n\n\n\n<li><code>tribe\/event-organizer<\/code><\/li>\n\n\n\n<li><code>tribe\/event-venue<\/code><\/li>\n\n\n\n<li><code>tribe\/event-website<\/code><\/li>\n\n\n\n<li><code>tribe\/event-links<\/code><\/li>\n<\/ul>\n\n\n\n<p>Here are a few examples of how you would use this, such as removing the Price block or changing\u00a0the whole template.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-remove-the-price-block\">Remove the Price block<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\nadd_filter( &#039;tribe_events_editor_default_template&#039;, function( $template ) {\n\t\/\/ collect an array of template values, like &quot;tribe\/event-price&quot; and tribe\/event-venue&quot;\n\t$template_search = array_column( $template, 0 );\n\n\t\/\/ Get the index of the &quot;tribe\/event-price&quot;\n\t$price = array_search( &quot;tribe\/event-price&quot;, $template_search );\n\n\t\/\/ @link: https:\/\/www.php.net\/manual\/en\/function.array-splice.php\n\tarray_splice(\n\t\t\/\/ The original $template array\n\t\t$template,\n\t\t\/\/ The integer value of the price index (such as 2)\n\t\t$price,\n\t\t\/\/ How many items we want to remove from $template (just 1: the price)\n\t\t1\n\t);\n\n\t\/\/ Return the price-spliced $template\n\treturn $template;\n}, 11, 1 );\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-change-the-template\">Change the template<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\nadd_filter( &#039;tribe_events_editor_default_template&#039;, function( $template ) {\n  $template = &#x5B;\n    &#x5B; &#039;tribe\/event-datetime&#039; ],\n    &#x5B; &#039;core\/paragraph&#039;, &#x5B;\n      &#039;placeholder&#039; =&gt; __( &#039;Add Description...&#039;, &#039;the-events-calendar&#039; ),\n    ], ],\n    &#x5B; &#039;tribe\/event-organizer&#039; ],\n    &#x5B; &#039;tribe\/event-venue&#039; ],\n  ];\n  return $template;\n}, 11, 1 );\n<\/pre><\/div>\n\n\n<p>It&#8217;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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Adding more WordPress core blocks when changing the template<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>As an example, if you need to include the Featured Image block, you&#8217;ll need to include the <code>['core\/post-featured-image']<\/code> on the position you want to appear.<\/p>\n\n\n\n<p>Let&#8217;s see how you can add it before the paragraph block:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\nadd_filter( &#039;tribe_events_editor_default_template&#039;, function( $template ) {\n  $template = &#x5B;\n    &#x5B; &#039;tribe\/event-datetime&#039; ],\n    &#x5B; &#039;core\/post-featured-image&#039; ],\n    &#x5B; &#039;core\/paragraph&#039;, &#x5B;\n      &#039;placeholder&#039; =&gt; __( &#039;Add Description...&#039;, &#039;the-events-calendar&#039; ),\n    ], ],\n    &#x5B; &#039;tribe\/event-organizer&#039; ],\n    &#x5B; &#039;tribe\/event-venue&#039; ],\n  ];\n  return $template;\n}, 11, 1 );\n<\/pre><\/div>\n\n\n<p>You can find a list of all default WordPress blocks at <a href=\"https:\/\/developer.wordpress.org\/block-editor\/reference-guides\/core-blocks\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/developer.wordpress.org\/block-editor\/reference-guides\/core-blocks\/<\/a> and use their &#8220;Name&#8221; to include them on that list.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-remove-the-related-events-block\">Remove the Related Events Block<\/h2>\n\n\n\n<p>The following code snippet assists in removing the Related Events block from the default template,<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/masoodahmed\/c2f1e0d041a773f8e2ab2d9dfd29a89c.js\"><\/script>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-remove-rsvp-tickets-and-attendees-block\">Remove RSVP, Tickets, and Attendees Block<\/h2>\n\n\n\n<p>The following code snippet removes the RSVP, Tickets, and Attendees blocks added by the Event Tickets plugin,<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/masoodahmed\/569cc12cdeb514c440ca23f8293bea6a.js\"><\/script>\n","protected":false},"excerpt":{"rendered":"<p>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. We have a list of default blocks loaded by&#8230;<\/p>\n","protected":false},"author":2,"featured_media":1955565,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_swpsp_post_exclude":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"ep_exclude_from_search":false,"footnotes":""},"categories":[24,59,79],"tags":[113,20,25,58],"stellar-product-taxonomy":[155,158,161],"class_list":["post-1896710","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-customizing","category-customizing-resources","category-snippets","tag-block-editor","tag-code","tag-customizations","tag-php","stellar-product-taxonomy-event-tickets","stellar-product-taxonomy-events-calendar-pro","stellar-product-taxonomy-the-events-calendar"],"acf":[],"taxonomy_info":{"category":[{"value":24,"label":"Customizations"},{"value":59,"label":"PHP &amp; Functions"},{"value":79,"label":"Snippets"}],"post_tag":[{"value":113,"label":"block editor"},{"value":20,"label":"Code"},{"value":25,"label":"Customizations"},{"value":58,"label":"PHP"}],"stellar-product-taxonomy":[{"value":155,"label":"Event Tickets"},{"value":158,"label":"Events Calendar Pro"},{"value":161,"label":"The Events Calendar"}]},"featured_image_src_large":["https:\/\/images.theeventscalendar.com\/kb\/uploads\/2023\/02\/social-share-1024x538.png",1024,538,true],"author_info":{"display_name":"zach","author_link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/author\/zach\/"},"comment_info":0,"category_info":[{"term_id":24,"name":"Customizations","slug":"customizing","term_group":0,"term_taxonomy_id":24,"taxonomy":"category","description":"","parent":0,"count":110,"filter":"raw","term_order":"0","cat_ID":24,"category_count":110,"category_description":"","cat_name":"Customizations","category_nicename":"customizing","category_parent":0},{"term_id":59,"name":"PHP &amp; Functions","slug":"customizing-resources","term_group":0,"term_taxonomy_id":59,"taxonomy":"category","description":"","parent":24,"count":101,"filter":"raw","term_order":"0","cat_ID":59,"category_count":101,"category_description":"","cat_name":"PHP &amp; Functions","category_nicename":"customizing-resources","category_parent":24},{"term_id":79,"name":"Snippets","slug":"snippets","term_group":0,"term_taxonomy_id":79,"taxonomy":"category","description":"","parent":0,"count":136,"filter":"raw","term_order":"0","cat_ID":79,"category_count":136,"category_description":"","cat_name":"Snippets","category_nicename":"snippets","category_parent":0}],"tag_info":[{"term_id":113,"name":"block editor","slug":"block-editor","term_group":0,"term_taxonomy_id":113,"taxonomy":"post_tag","description":"","parent":27,"count":17,"filter":"raw","term_order":"0"},{"term_id":20,"name":"Code","slug":"code","term_group":0,"term_taxonomy_id":20,"taxonomy":"post_tag","description":"","parent":0,"count":33,"filter":"raw","term_order":"0"},{"term_id":25,"name":"Customizations","slug":"customizations","term_group":0,"term_taxonomy_id":25,"taxonomy":"post_tag","description":"","parent":0,"count":177,"filter":"raw","term_order":"0"},{"term_id":58,"name":"PHP","slug":"php","term_group":0,"term_taxonomy_id":58,"taxonomy":"post_tag","description":"","parent":20,"count":128,"filter":"raw","term_order":"0"}],"_links":{"self":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1896710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=1896710"}],"version-history":[{"count":10,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1896710\/revisions"}],"predecessor-version":[{"id":1962809,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1896710\/revisions\/1962809"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media\/1955565"}],"wp:attachment":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=1896710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1896710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1896710"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1896710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}