Skip to content

Instantly share code, notes, and snippets.

@siayi
Forked from mrwweb/readme.md
Created August 13, 2022 14:11
Show Gist options
  • Save siayi/a89e486c8be67f34246192e692435ca0 to your computer and use it in GitHub Desktop.
Save siayi/a89e486c8be67f34246192e692435ca0 to your computer and use it in GitHub Desktop.
The Events Calendar v2 Template Reset & Customizations

The Events Calendar v2 Template Reset & Customizations

Version 1.5

Introduction

The Events Calendar is a very powerful WordPress plugin for managing events. However, the way its templates and CSS are implemented—especially in "v2"—leave much to be desired.

This contains all the changes I make on a project for The Events Calendar. Hopefully it's useful. If it saves you an hour, maybe you can buy me a cup of coffee or a beer 🍻

Customizations Checklist

  • Copy and customize BOTH default-template.php files into theme folders
    • /tribe-events/default-template.php - Old version of file, still used for single events
    • /tribe/events/v2/default-template.php - Used for new Month, List, Day, etc. views
  • Clean up one or both single event templates:
    • Classic Editor Events: single-event.php
    • Block Editor Events: single-event-blocks.php
  • Customize additional templates as needed. Recommended:
    • tribe/events/v2/list/month-separator.php - Should use a Heading 2 for better heading structure
    • tribe/events/v2/list/event.php - Date/time should follow the event's title heading for logical structure
    • tribe/events/v2/latest-past/event.php - Date/time should follow the event's title heading for logical structure
    • tribe/events/blocks/event-datetime.php - Don't use a Heading 2 for logical heading structure on single events
    • tribe/events/v2/list/event/date-tag.php - Apply aria-hidden="true" to redundant date information that's outside of logical heading structure
    • tribe/events/v2/latest-past/event/date-tag.php - Apply aria-hidden="true" to redundant date information that's outside of logical heading structure
    • tribe/events/v2/list/event/feature-image.php - Apply aria-hidden="true" and tabindex="-1" to featured image link since it's redundant with the event title link in list view
    • tribe/events/v2/latest-past/event/feature-image.php - Apply aria-hidden="true" and tabindex="-1" to featured image link since it's redundant with the event title link in list view
  • Fix a few things about event pages and set custom default block template with mu-plugin in the-events-calendar-customizations.php
  • Use tec-resets.scss reset stylesheet below to get rid of hard-coded
    • Set CSS properties to match theme font sizes and colors
    • Note use of SCSS nested selectors because that's what I use
  • Add custom styles to blocks.
  • (Optional) Install plugin to hide Export links https://theeventscalendar.com/extensions/remove-export-links/

Useful v2 Design Filters

In v2 templates, you can use the tribe_template_pre_html filter to hide specific template parts. For example, to hide the "Read More" links in list views:

/* Hide "Read More" links */
add_filter( 'tribe_template_pre_html:events/v2/components/read-more', '__return_false' );

You can also helpfully add content before or after any template part using tribe_template_before_include and tribe_template_after_include. For example:

/* Add "Hello World" after the "Views" selector in the event bar */
add_action( 'tribe_template_before_include:events/v2/components/events-bar/views', function( $file, $name, $template ) {
  echo 'Hello World';
}, 10, 3 );

References:

Todos

  • Add new override selectors for new Single Event view released in 5.5

Changlog

1.5.0 (August 05, 2022)

  • Remove font-family now that there's a customizer setting for it

1.4.2 (May 03, 2022)

  • Attempt to improve subscribe button style overrides dealing with weird focus and hover behaviors. Absolute position dropdown to avoid layout jank

1.4.1 (February 9, 2022)

  • Improvements to subscribe button overrides to make them more likely to win over unwanted theme styles

1.4.0 (January 19, 2022)

  • Fix featured event styles in month view
  • Add styles to override subscribe button styles
  • New suggestion to hide featured image from assistive technology in list views
  • Add equivalent template changes to /latest-past/ templates to match /list/ changes where applicable

1.3.0 (August 23, 2021)

  • Add new selectors for heading styles and links on the new single event templates to match other override styles (fonts, underlining behavior, etc.)
  • Increase specificity of .tribe-common-c-btn selectors in order to override messed up settings in plugin and ensure the search bar button is the correct color
  • Remove filter that hid the back link on the single template. Does not work in v2 single events.

1.2.0 (June 18, 2021)

  • Add new selectors to inherit font styles from the theme
  • Add editor selectors to try to style blocks closer to front-end. Results will vary.
  • Bug fix for TEC 5.7.0 template_include filter

1.1.0 (April 20, 2021)

  • Add /v2/ to path of tribe_template_before_include filter to fix bug in TEC 5.5.
  • Remove errant SASS variable in style resets
  • Fix missing accent customization for Featured Styles in list view. Adds new --tec-accent-color variable that defaults to --tec-link-color

About

I'm Mark Root-Wiley of MRW Web Design. I build WordPress websites for nonprofits. Checkout my free resource site Nonprofit WP and my free plugins.

<?php
/**
* Examples of Block Templates that can be used with `tribe_events_editor_default_template` filter
*/
/**
* Simple starter template with fewer blocks
*/
$template = [
[ 'tribe/event-datetime' ],
[ 'core/paragraph', [ 'placeholder' => __( 'Add Description…', 'the-events-calendar' ), ], ],
[ 'tribe/event-website' ],
[ 'tribe/event-venue' ],
];
/**
* Two-column Venue / Organizer starter template
*/
$template = [
[ 'tribe/event-datetime' ],
[
'core/paragraph',
[
'placeholder' => __( 'Add Event Description...', 'the-events-calendar' ),
],
],
[ 'tribe/event-website' ],
[
'core/columns',
[
'backgroundColor' => 'faint-gray',
],
[
[
'core/column', [], [ [ 'tribe/event-venue' ] ]
],
[
'core/column', [], [ [ 'tribe/event-organizer' ] ]
]
]
],
];
/**
* Event Details "Card" Template with two-column Venue/Organizer
* You will likely need to change the color and font-size variables
*/
$template = [
[
'core/paragraph',
[ 'placeholder' => 'Event Description…', ],
],
[
'core/group',
[ 'backgroundColor' => 'white', 'align' => 'wide' ],
[
[ 'tribe/event-datetime' ],
[
'core/columns', [ 'align' => 'wide' ],
[
[
'core/column', [],
[
[
'core/heading',
[
'level' => 2,
'content' => 'Where',
'fontSize' => 'med',
'textColor' => 'fern',
'className' => 'is-style-bottom-rule',
]
],
[ 'tribe/event-venue' ]
]
],
[
'core/column', [],
[
[
'core/heading',
[
'level' => 2,
'content' => 'Organizer',
'fontSize' => 'med',
'textColor' => 'fern',
'className' => 'is-style-bottom-rule',
]
],
[ 'tribe/event-organizer' ]
]
],
]
],
[ 'tribe/event-website' ],
]
],
[
'core/paragraph',
[ 'placeholder' => 'Additional Event Details…', ],
],
];
<?php
/*
Plugin Name: The Events Calendar Customizations
Description: Changes the default Events block template. Disables "Events" toolbar menu.
Version: 1.5.0
Author: Mark Root-Wiley, MRW Web Design
Author URI: https://MRWweb.com
*/
namespace MRW\TEC;
add_action( 'tribe_template_before_include:events/v2/components/messages', 'MRW\TEC\events_archive_header' );
/**
* Add Title and Description to Event Archive Pages
*
* Use Post Type Archive Descriptions plugin to edit archive description
* https://wordpress.org/plugins/post-type-archive-descriptions/
*/
function events_archive_header() {
echo '<div class="my-events-header">';
the_archive_title( '<h1 class="archive-title">', '</h1>' );
if( is_archive() ) {
the_archive_description( '<div class="archive-description">', '</div>' );
}
echo '</div>';
// Fix bug resulting in double output in TEC 5.7.0
remove_action( 'tribe_template_before_include:events/v2/components/messages', 'MRW\TEC\events_archive_header' );
}
add_filter( 'get_the_archive_title', 'MRW\TEC\archive_title' );
/**
* Change "Events" to "Upcoming Events" for List/Month/Day page
*/
function archive_title( $title ) {
if( 'tribe_events' === get_post_type() ) {
$title = 'Upcoming Events';
}
return $title;
}
add_filter( 'tribe_events_editor_default_template', 'MRW\TEC\default_blocks', 11 );
/**
* Change default blocks when creating a new event with the Block Editor
*
* @see https://support.theeventscalendar.com/807454-Change-the-Default-Event-Template-in-Block-Editor
*/
function default_blocks( $template ) {
$template = [
[ 'tribe/event-datetime' ],
[ 'core/paragraph', [
'placeholder' => __( 'Add Description…', 'the-events-calendar' ),
], ],
[ 'tribe/event-website' ],
[ 'tribe/event-venue' ],
];
return $template;
}
/**
* Remove "Events" menu from WordPress admin bar
*
* @see https://theeventscalendar.com/knowledgebase/k/remove-events-from-the-wordpress-admin-bar/
*/
define( 'TRIBE_DISABLE_TOOLBAR_ITEMS', true );
/**
* The Events Calendar v2 Design Style Resets & Fixes
* Version: 1.5.0
* Details: https://gist.github.com/mrwweb/6f5ba48873d9bd24dfc23eed7ad934df
*/
/**
* Set these values to make TEC use your theme's styles
*
* Note: If you're using SASS variables to fill these in, do so like this: #{$variable}
* Note about note: The variable reference on the previous line may prevent compiling sass. Remove it once you're done with it.
*/
:root {
--tec-link-color: ; /* used for links and buttons. Should have 4.5:1+ contrast with white */
--tec-link-color-hover: ;
--tec-accent-color: var(--tec-link-color); /* Can be different from the link color if you like. */
--tec-heading-weight: ;
--tec-highlight-color: ;
--tec-heading-2-size: ;
--tec-heading-3-size: ;
--tec-heading-color: ;
--tec-container-background: #fff; // set to background color of container for month/list/day views
}
/* Remove Excessive extra padding */
.tribe-common--breakpoint-medium.tribe-events .tribe-events-l-container {
padding: 0;
}
/* Match overlay color to container background */
.tribe-events .tribe-events-view-loader {
background-color: var(--tec-container-background);
opacity: 0.7;
}
/* Inherit font size, line height, font weight, and color */
.tribe-common--breakpoint-medium.tribe-events .tribe-events-c-breadcrumbs__list,
.tribe-events .datepicker .month,
.tribe-events .datepicker .year,
.tribe-events-schedule__all-day,
.tribe-events-schedule__separator,
.tribe-events-schedule__timezone,
.tribe-events-meta-group .tribe-events-single-section-title,
.tribe-common .tribe-common-b1,
.tribe-common .tribe-common-b2,
.tribe-common--breakpoint-medium.tribe-common .tribe-common-b2,
.tribe-common--breakpoint-medium.tribe-common .tribe-common-b1--min-medium,
.tribe-common--breakpoint-medium.tribe-common .tribe-common-b2--min-medium,
.tribe-common--breakpoint-medium.tribe-common .tribe-common-b3--min-medium,
.tribe-common--breakpoint-medium.tribe-common .tribe-common-h6--min-medium,
.tribe-common .tribe-common-cta,
.tribe-common .tribe-events-c-top-bar__datepicker-button.tribe-common-h3,
.tribe-block__venue .tribe-block__venue__meta .tribe-block__venue__address,
.tribe-block__venue .tribe-block__venue__meta .tribe-block__venue__phone,
.tribe-block__venue .tribe-block__venue__meta .tribe-block__venue__website,
.tribe-events-schedule__time,
.tribe-events-schedule__date,
.tribe-block__organizer__details p,
.tribe-editor__subtitle .tribe-editor__btn--label,
.tribe-editor__subtitle__headline-date,
.tribe-editor__separator,
.tribe-editor__venue__address,
.tribe-editor__venue__phone,
.tribe-editor__venue__website,
div .tribe-editor__organizer__details p,
.tribe-editor__event-website__label-text input {
font-size: inherit;
line-height: inherit;
color: inherit;
font-weight: inherit;
}
/* Set Heading Weight */
h2.tribe-events-schedule__datetime,
.tribe-common .tribe-common-h1,
.tribe-common .tribe-common-h2,
.tribe-common .tribe-common-h3,
.tribe-common .tribe-common-h4,
.tribe-common .tribe-common-h5,
.tribe-common .tribe-common-h6,
.tribe-common .tribe-common-h7,
.tribe-common .tribe-common-h8,
.tribe-events-calendar-latest-past__event-datetime,
.tribe-events-calendar-list__event-datetime,
.tribe-events-meta-group .tribe-events-single-section-title,
.tribe-block__organizer__details h3,
.tribe-block__venue .tribe-block__venue__meta .tribe-block__venue__name h3,
.tribe-editor__venue
.tribe-editor__venue__name
h3.tribe-editor__venue__name-heading,
.tribe-events-single-event-title,
.tribe-events-content h2,
.tribe-events-content h3,
.tribe-events-content h4,
.tribe-events-content h5,
.tribe-events-content h6 {
font-weight: var(--tec-heading-weight);
}
/* Style List Month Separator like Heading 2 */
:root
.tribe-common
.tribe-common-h6--min-medium.tribe-events-calendar-list__month-separator-text {
font-size: inherit;
font-weight: var(--tec-heading-weight);
}
/* Fix Hard-coded Heading 3 Size */
:root
.tribe-block__venue
.tribe-block__venue__meta
.tribe-block__venue__name
h3,
.tribe-block__organizer__details h3,
.tribe-editor__venue
.tribe-editor__venue__name
h3.tribe-editor__venue__name-heading {
font-size: var(--tec-heading-3-size);
}
/* Don't put box around Date/Time Block on Mobile */
.single-tribe_events .tribe-events-schedule {
margin: 0;
padding: 0;
background-color: transparent;
border: 0;
}
/**
* Links & Buttons
*/
.tribe-common a,
#tribe-events-content a,
.tribe-common .tribe-common-c-svgicon,
.tribe-events-single-event-description a,
.tribe-events-single-event-description a:active,
.tribe-events-single-event-description a:focus,
.tribe-events-single-event-description a:hover,
.tribe-events-content blockquote {
&,
&:active,
&:visited {
color: var(--tec-link-color);
text-decoration: underline;
}
&:focus,
&:hover {
color: var(--tec-link-color-hover);
text-decoration: none;
}
}
.tribe-common .tribe-common-anchor-thin,
.tribe-common .tribe-common-anchor-thin-alt,
.tribe-events-single-event-description a,
.tribe-events-single-event-description a:active,
.tribe-events-single-event-description a:focus,
.tribe-events-single-event-description a:hover,
.tribe-events-content blockquote {
&,
&:hover,
&:focus {
border-bottom: 0;
}
}
.tribe-common.tribe-common.tribe-common .tribe-common-c-btn,
.tribe-common.tribe-common.tribe-common a.tribe-common-c-btn {
background-color: var(--tec-link-color);
&:hover,
&:focus {
background-color: var(--tec-link-color);
filter: brightness(1.2);
}
}
.tribe-events .tribe-events-c-ical__link {
border-color: var(--tec-link-color);
color: var(--tec-link-color);
text-decoration: none;
&:hover,
&:focus {
background-color: var(--tec-link-color);
border: 1px solid var(--tec-link-color);
}
}
/**
* List View
*/
/* Featured Event UI Colors */
.tribe-common--breakpoint-medium.tribe-events
.tribe-events-calendar-list__event-datetime-featured-text {
color: var(--tec-accent-color);
font-weight: var(--tec-heading-weight);
}
.tribe-events
.tribe-events-calendar-list__event-row--featured
.tribe-events-calendar-list__event-date-tag-datetime::after {
background-color: var(--tec-highlight-color);
}
/**
* Month View
*/
/* Don't show disabled paging links */
.tribe-events-c-nav__list [disabled] {
display: none;
}
/* Highlights Today in month and day view */
.tribe-events
.tribe-events-calendar-month__day--current
.tribe-events-calendar-month__day-date,
.tribe-events
.tribe-events-calendar-month__day--current
.tribe-events-calendar-month__day-date-link {
color: var(--tec-highlight-color);
}
.tribe-events .datepicker .day.active,
.tribe-events .datepicker .day.active.focused,
.tribe-events .datepicker .day.active:focus,
.tribe-events .datepicker .day.active:hover,
.tribe-events .datepicker .month.active,
.tribe-events .datepicker .month.active.focused,
.tribe-events .datepicker .month.active:focus,
.tribe-events .datepicker .month.active:hover,
.tribe-events .datepicker .year.active,
.tribe-events .datepicker .year.active.focused,
.tribe-events .datepicker .year.active:focus,
.tribe-events .datepicker .year.active:hover {
background-color: var(--tec-link-color);
}
/* Hover border on day of the month */
.tribe-common--breakpoint-medium.tribe-events
.tribe-events-calendar-month__day:hover::after {
background-color: var(--tec-highlight-color);
}
/**
* Subscribe Button
*/
.tribe-events-c-subscribe-dropdown__content {
position: absolute;
}
.tribe-events
.tribe-events-c-subscribe-dropdown
.tribe-events-c-subscribe-dropdown__button {
border-color: var(--tec-link-color);
color: var(--tec-link-color);
}
.tribe-events
.tribe-events-c-subscribe-dropdown
.tribe-events-c-subscribe-dropdown__button-text {
color: inherit !important;
}
.tribe-events
.tribe-events-c-subscribe-dropdown
.tribe-events-c-subscribe-dropdown__button.tribe-events-c-subscribe-dropdown__button--active,
.tribe-events
.tribe-events-c-subscribe-dropdown
.tribe-events-c-subscribe-dropdown__button:focus,
.tribe-events
.tribe-events-c-subscribe-dropdown
.tribe-events-c-subscribe-dropdown__button:focus-within,
.tribe-events
.tribe-events-c-subscribe-dropdown
.tribe-events-c-subscribe-dropdown__button:hover,
.tribe-events
.tribe-events-c-subscribe-dropdown
.tribe-events-c-subscribe-dropdown__button:hover,
.tribe-events
.tribe-events-c-subscribe-dropdown:focus
.tribe-events-c-subscribe-dropdown__button-text,
.tribe-events
.tribe-events-c-subscribe-dropdown
.tribe-events-c-subscribe-dropdown__button-text:focus,
.tribe-events .tribe-events-c-subscribe-dropdown:focus-within {
border-color: var(--tec-link-color);
background-color: var(--tec-link-color);
color: #fff !important;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment