Skip to main content

Modifying the Event Calendar HTML

The calendar is printed by a set of template files, so you can change its markup by copying one of them to an override folder and editing the copy. This page lists the files and the data they receive.

Before you override anything, check whether a setting already does what you want. The calendar's size, how events are drawn in each day and the preview behavior are options in Events then Settings then Formatting then Calendar and attributes of the calendar shortcode, and colors come from event categories.

Before you start

Read Using Template Files for where override files go. This page describes the templates in Events Manager 7.5.

The calendar templates​

Since version 6, one set of files in events-manager/templates/calendar/ prints every calendar, large or small.

FilePrints
calendar/calendar.phpThe calendar wrapper. Includes the sections below in order.
calendar/section-header-navigation.phpThe month name, the previous, next and today links, and the month picker
calendar/section-header-weekdays.phpThe row of weekday names
calendar/section-dates.phpThe grid of days and the events in each
calendar/section-preview-content.phpThe hidden content used for event and date previews
calendar/preview-event-modal.php, preview-event-tooltip.php, preview-date-modal.phpThe preview pop-ups

Override the smallest file that contains what you want to change. To change how a day cell is built, copy only section-dates.php:

wp-content/plugins/events-manager/templates/calendar/section-dates.php
wp-content/plugin-templates/events-manager/calendar/section-dates.php
Older overrides

Before version 6 the calendar was printed by templates/calendar-full.php and templates/calendar-small.php. Those two files still exist, and Events Manager still loads an override of either one if it finds it, but the originals now only include calendar/calendar.php. An override written for version 5 produces the old table markup, which the current calendar styles and scripts don't support. Rebuild it from the files above.

Data available in the templates​

Each calendar template has two variables: $args, the cleaned search attributes the calendar was requested with, and $calendar, an array describing the month.

KeyContains
cellsOne entry per day shown in the grid, keyed by date as Y-m-d. Includes the days from the months before and after that fill the first and last weeks.
month, yearThe month and year being shown
month_startTimestamp of the first day of the month
timezoneThe timezone the calendar is shown in
row_headersThe weekday labels, in the site's week order. row_headers_large and row_headers_small hold longer and shorter versions for different calendar sizes.
linksprevious_url, next_url and today_url for navigation. A link is empty when there is nowhere to go.
cssArrays of CSS classes for the wrapper (calendar_classes) and the dates grid (dates_classes)
argsThe same cleaned arguments as $args

Each entry in cells is an array:

KeyContains
dateTimestamp of the day
typepre for a day in the previous month, post for one in the next month, today for today. Not set for other days.
eventsThe EM_Event objects taking place that day, if any
events_countHow many events the day has
linkAddress of the page listing that day's events, when the day has events
link_titleText for that link's title attribute

Example: mark days that have events​

This adds a small count under the date number of each day with events. It is a change to a copy of section-dates.php. Find where the template prints the day's number, and add after it:

In your copy of calendar/section-dates.php
<?php if ( ! empty( $cell_data['events_count'] ) ) : ?>
<span class="my-day-count">
<?php
/* translators: %d: number of events */
echo esc_html( sprintf( _n( '%d event', '%d events', $cell_data['events_count'], 'my-plugin' ), $cell_data['events_count'] ) );
?>
</span>
<?php endif; ?>

$cell_data is the name the template gives each entry of $calendar['cells'] inside its loop.

Keep the existing class names and data- attributes on the elements you leave in place. Navigation without a page reload, the month picker, search and previews all find their elements through them.

Change the data instead of the markup​

To alter what the templates receive, for example to remove some events from certain days, filter the array before it reaches them:

add_filter( 'em_calendar_get', function ( $calendar, $args ) {
// Change $calendar['cells'] here.
return $calendar;
}, 10, 2 );

Test it​

  1. View a page with a calendar and confirm your change shows.
  2. Click the next and previous month links. The calendar should change month without reloading the page and still show your change.
  3. Click a day or an event to check that previews still open.

If the calendar stops responding after your change, compare your copy with the original for a class or attribute you removed.