{"id":1948280,"date":"2020-10-22T07:22:12","date_gmt":"2020-10-22T11:22:12","guid":{"rendered":"https:\/\/theeventscalendar.com\/knowledgebase\/?post_type=tribe-knowledgebase&#038;p=1948280"},"modified":"2026-04-17T13:06:22","modified_gmt":"2026-04-17T17:06:22","slug":"template-filters-hooks-actions","status":"publish","type":"post","link":"https:\/\/theeventscalendar.com\/knowledgebase\/template-filters-hooks-actions\/","title":{"rendered":"Using Template Filters, Hooks, and Actions with The Events Calendar"},"content":{"rendered":"\n<p>The Events Calendar&#8217;s template system provides several PHP entry points for injecting content into, modifying, or completely bypassing the default calendar templates \u2014 without editing the template files themselves. This article covers all three layers: before\/after hooks, output filters, and the template hierarchy filter.<\/p>\n\n\n\n<p>All of these techniques work with the <a href=\"https:\/\/docs.theeventscalendar.com\/reference\/classes\/Tribe__Template\/\"><code>Tribe__Template<\/code><\/a> class, which handles locating template files, passing context variables, and triggering hooks and filters each time a template is loaded.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-before-and-after-hooks\">Before and After Hooks<\/h2>\n\n\n\n<p>Every calendar view template has a <code>before<\/code> and <code>after<\/code> hook that lets you insert custom HTML either above or below the template without modifying the file. The hook name follows this pattern:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tribe_template_before_include:events\/v2\/{template-path}<\/code><\/li>\n\n\n\n<li><code>tribe_template_after_include:events\/v2\/{template-path}<\/code><\/li>\n<\/ul>\n\n\n\n<p>The three arguments passed to the callback are <code>$file<\/code> (the full template path as a string), <code>$name<\/code> (the template name as an array of path parts), and <code>$template<\/code> (the current <code>Tribe__Template<\/code> instance). You won&#8217;t need to work with these in most cases.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-adding-event-author-below-the-title\">Example: Adding Event Author Below the Title<\/h3>\n\n\n\n<p>We&#8217;ll use <code>tribe_template_before_include<\/code> to display the event author below the title, above the venue information, in List view.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/theeventscalendar.com\/knowledgebase\/wp-content\/uploads\/2020\/01\/article-1-version-5-0-image-1-1024x407.png\" alt=\"The List view event showing where the event author will be inserted, below the title and above the venue\"\/><\/figure>\n\n\n\n<p>First, create the following file in your theme: <code>tribe\/events\/v2\/list\/event-author.php<\/code><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;div class=&quot;tribe-common-b2&quot;&gt;\n  Author: &amp;lt;?php the_author(); ?&gt;\n&amp;lt;\/div&gt;\n<\/pre><\/div>\n\n\n<p>Then add the action to your theme&#8217;s <code>functions.php<\/code>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nadd_action(\n  &#039;tribe_template_before_include:events\/v2\/list\/event\/venue&#039;,\n  function ( $file, $name, $template ) {\n    $template-&gt;template( &#039;list\/event-author&#039; );\n  },\n  10,\n  3\n);\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/theeventscalendar.com\/knowledgebase\/wp-content\/uploads\/2020\/01\/article-1-version-5-0-image-2-1024x539.png\" alt=\"The List view after the hook is added, showing the event author displayed below the title\"\/><\/figure>\n\n\n\n<p>Event templates in TEC are set up to work with standard WordPress post functions, so functions like <code>the_author()<\/code> work exactly as you&#8217;d expect.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-marking-events-on-christmas-day\">Example: Marking Events on Christmas Day<\/h3>\n\n\n\n<p>This example uses <code>tribe_template_after_include<\/code> to display emojis after the date on events that fall on December 24th or 25th.<\/p>\n\n\n\n<p>Create <code>tribe\/events\/v2\/list\/christmas-marker.php<\/code> in your theme:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?php\n$event = tribe_get_event( get_the_ID() );\n$christmas_days = &#x5B; &#039;12-24&#039;, &#039;12-25&#039; ];\n\nif ( ! in_array( $event-&gt;dates-&gt;start-&gt;format( &#039;m-d&#039; ), $christmas_days, true ) ) {\n  return;\n}\n?&gt;\n&amp;lt;span&gt;\ud83c\udf84&amp;lt;\/span&gt;\n<\/pre><\/div>\n\n\n<p>Then add the action to <code>functions.php<\/code>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nadd_action(\n  &#039;tribe_template_after_include:events\/v2\/list\/event\/date\/meta&#039;,\n  function ( $file, $name, $template ) {\n    $template-&gt;template( &#039;list\/christmas-marker&#039; );\n  },\n  10,\n  3\n);\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/theeventscalendar.com\/knowledgebase\/wp-content\/uploads\/2020\/01\/article-1-version-5-0-image-3-1024x766.png\" alt=\"The List view showing Christmas tree emojis added after the date on events falling on December 24th or 25th\"\/><\/figure>\n\n\n\n<p>This example uses <a href=\"https:\/\/docs.theeventscalendar.com\/reference\/functions\/tribe_get_event\/\"><code>tribe_get_event()<\/code><\/a>, which returns a <code>WP_Post<\/code>-like object tailored for events. The <code>$event-&gt;dates-&gt;start<\/code> property is a PHP <a href=\"https:\/\/www.php.net\/manual\/en\/class.datetimeimmutable.php\"><code>DateTimeImmutable<\/code><\/a> instance, giving you access to all standard date formatting methods. Using <code>format_i18n()<\/code> instead of <code>format()<\/code> will translate dates where translations are available.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-output-filters\">Output Filters<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-suppressing-a-template-part\">Suppressing a Template Part<\/h3>\n\n\n\n<p>You can short-circuit the rendering of any template entirely using the <code>tribe_template_pre_html:$template<\/code> filter. This prevents the HTML from being generated at all, which is better for performance than hiding it with CSS.<\/p>\n\n\n\n<p>The following removes the venue from events in Day view only:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nadd_filter( &#039;tribe_template_pre_html:events\/v2\/day\/event\/venue&#039;, &#039;__return_false&#039; );\n<\/pre><\/div>\n\n\n<p>The <code>__return_false<\/code> WordPress helper always returns boolean <code>false<\/code>, which signals the template engine to skip rendering that file. Note that unlike actions, WordPress filters always require a value to be returned.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-full-hook-and-filter-reference\">Full Hook and Filter Reference<\/h3>\n\n\n\n<p>All view files in TEC are loaded through the <code>Tribe__Template<\/code> class, which triggers the following hooks and filters on every template load. The <code>:$template<\/code> suffix variants allow you to target a specific template file; the unsuffixed variants fire for every template.<\/p>\n\n\n\n<p><strong>Filters:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/docs.theeventscalendar.com\/reference\/hooks\/tribe_template_pre_html\/\"><code>tribe_template_pre_html<\/code><\/a> \u2014 fires before HTML generation for any template<\/li>\n\n\n\n<li><a href=\"https:\/\/docs.theeventscalendar.com\/reference\/hooks\/tribe_template_pre_htmlhook_name\/\"><code>tribe_template_pre_html:$template<\/code><\/a> \u2014 fires before HTML generation for a specific template<\/li>\n\n\n\n<li><a href=\"https:\/\/docs.theeventscalendar.com\/reference\/hooks\/tribe_template_html\/\"><code>tribe_template_html<\/code><\/a> \u2014 fires after HTML generation for any template, allowing output modification<\/li>\n\n\n\n<li><a href=\"https:\/\/docs.theeventscalendar.com\/reference\/hooks\/tribe_template_htmlhook_name\/\"><code>tribe_template_html:$template<\/code><\/a> \u2014 fires after HTML generation for a specific template<\/li>\n<\/ul>\n\n\n\n<p><strong>Actions:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/docs.theeventscalendar.com\/reference\/hooks\/tribe_template_before_include\/\"><code>tribe_template_before_include<\/code><\/a> \u2014 fires before any template is included<\/li>\n\n\n\n<li><a href=\"https:\/\/docs.theeventscalendar.com\/reference\/hooks\/tribe_template_before_includehook_name\/\"><code>tribe_template_before_include:$template<\/code><\/a> \u2014 fires before a specific template is included<\/li>\n\n\n\n<li><a href=\"https:\/\/docs.theeventscalendar.com\/reference\/hooks\/tribe_template_after_include\/\"><code>tribe_template_after_include<\/code><\/a> \u2014 fires after any template is included<\/li>\n\n\n\n<li><a href=\"https:\/\/docs.theeventscalendar.com\/reference\/hooks\/tribe_template_after_includehook_name\/\"><code>tribe_template_after_include:$template<\/code><\/a> \u2014 fires after a specific template is included<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-template-hierarchy-filter-template-hijack\">The Template Hierarchy Filter (Template Hijack)<\/h2>\n\n\n\n<p>The techniques above let you inject content into or suppress parts of TEC&#8217;s own templates. The Template Hierarchy filter goes further: it bypasses TEC&#8217;s template system entirely and tells WordPress to use its standard <a href=\"https:\/\/developer.wordpress.org\/themes\/basics\/template-hierarchy\/\">template hierarchy<\/a> for events instead. This lets you display calendar content using your existing theme templates, or build completely custom archive and single templates for events.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ntribe_events_views_v2_use_wp_template_hierarchy\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/theeventscalendar.com\/knowledgebase\/wp-content\/uploads\/2020\/10\/archive-1024x710.png\" alt=\"The events archive displayed using the theme's archive template instead of the plugin's calendar template\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-basic-usage\">Basic Usage<\/h3>\n\n\n\n<p>The filter&#8217;s primary argument is <code>$hijack<\/code> \u2014 a boolean that switches the calendar to WordPress template hierarchy when set to <code>true<\/code>. The three additional optional arguments are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>$template<\/code> \u2014 the template located by WordPress (e.g. <code>event-single.php<\/code>)<\/li>\n\n\n\n<li><code>$context<\/code> \u2014 the immutable global Tribe template context object<\/li>\n\n\n\n<li><code>$query<\/code> \u2014 the global <code>$wp_query<\/code><\/li>\n<\/ul>\n\n\n\n<p>This basic usage applies the hijack to all views except single event pages:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nadd_filter(\n  &#039;tribe_events_views_v2_use_wp_template_hierarchy&#039;,\n  function( $hijack, $template, $context, $query ) {\n    if ( ! is_singular() ) {\n      $hijack = true;\n    }\n    return $hijack;\n  },\n  10,\n  4\n);\n<\/pre><\/div>\n\n\n<p>To apply it to single event pages only:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nadd_filter(\n  &#039;tribe_events_views_v2_use_wp_template_hierarchy&#039;,\n  function( $hijack, $template, $context, $query ) {\n    if ( is_singular() ) {\n      $hijack = true;\n    }\n    return $hijack;\n  },\n  10,\n  4\n);\n<\/pre><\/div>\n\n\n<p>To hijack both archive and single at once:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nadd_filter( &#039;tribe_events_views_v2_use_wp_template_hierarchy&#039;, &#039;__return_true&#039; );\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-building-a-custom-event-archive-template\">Building a Custom Event Archive Template<\/h3>\n\n\n\n<p>When the hijack filter is active, the events archive behaves like any other custom post type archive. You can create a dedicated template for it by adding <code>archive-tribe_events.php<\/code> to your theme&#8217;s root folder \u2014 exactly as you would when <a href=\"https:\/\/developer.wordpress.org\/themes\/template-files-section\/custom-post-type-template-files\/#custom-post-type-templates\">creating an archive template for a custom post type<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/theeventscalendar.com\/knowledgebase\/wp-content\/uploads\/2020\/10\/archive-2-1024x674.png\" alt=\"The events archive displayed with a custom archive-tribe_events.php theme template\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-building-a-custom-single-event-template\">Building a Custom Single Event Template<\/h3>\n\n\n\n<p>Similarly, create <code>single-tribe_events.php<\/code> in your theme root to build a custom single event template. To access event-specific data (dates, venue, organizer, etc.) that isn&#8217;t available in a standard post template, call <code>tribe_get_event()<\/code> at the top of the file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$event = tribe_get_event( get_the_ID() );\n\nget_header();\n<\/pre><\/div>\n\n\n<p>From there, use the <code>$event<\/code> object to access event properties:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;h2&gt;\n  &amp;lt;?php echo esc_html( $event-&gt;title ); ?&gt;\n&amp;lt;\/h2&gt;\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/theeventscalendar.com\/knowledgebase\/wp-content\/uploads\/2020\/10\/single-altered-910x1024.png\" alt=\"A custom single-tribe_events.php template displaying event data retrieved via tribe_get_event()\"\/><\/figure>\n\n\n\n<p>\ud83d\udc4b <a href=\"https:\/\/theeventscalendar.com\/knowledgebase\/wp-content\/uploads\/2020\/10\/template-manager-filters.zip\">Download the example files<\/a> used in this section if you&#8217;d like to follow along with a working copy.<\/p>\n\n\n\n<p>With the Template Hierarchy filter you can: use your theme&#8217;s existing templates for calendar content, hijack single events, event archives, or both, create dedicated templates for each, and access all event data in those templates. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Events Calendar&#8217;s template system provides several PHP entry points for injecting content into, modifying, or completely bypassing the default calendar templates \u2014 without editing the template files themselves. This article covers all three layers: before\/after hooks, output filters, and the template hierarchy filter. All of these techniques work with the Tribe__Template class, which handles&#8230;<\/p>\n","protected":false},"author":3,"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":[84],"tags":[25,58],"stellar-product-taxonomy":[161],"class_list":["post-1948280","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-theming-overview","tag-customizations","tag-php","stellar-product-taxonomy-the-events-calendar"],"acf":[],"taxonomy_info":{"category":[{"value":84,"label":"Templating &amp; Layout"}],"post_tag":[{"value":25,"label":"Customizations"},{"value":58,"label":"PHP"}],"stellar-product-taxonomy":[{"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":"Jaime Marchwinski","author_link":"https:\/\/theeventscalendar.com\/knowledgebase\/author\/jaimetri-be\/"},"comment_info":0,"category_info":[{"term_id":84,"name":"Templating &amp; Layout","slug":"theming-overview","term_group":0,"term_taxonomy_id":84,"taxonomy":"category","description":"","parent":24,"count":25,"filter":"raw","term_order":"0","cat_ID":84,"category_count":25,"category_description":"","cat_name":"Templating &amp; Layout","category_nicename":"theming-overview","category_parent":24}],"tag_info":[{"term_id":25,"name":"Customizations","slug":"customizations","term_group":0,"term_taxonomy_id":25,"taxonomy":"post_tag","description":"","parent":0,"count":55,"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":44,"filter":"raw","term_order":"0"}],"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1948280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=1948280"}],"version-history":[{"count":4,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1948280\/revisions"}],"predecessor-version":[{"id":1969322,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1948280\/revisions\/1969322"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media\/1955565"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=1948280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1948280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1948280"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1948280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}