Skip to main content

Overriding Event Page Content With Filters

When users access the events page, Events Manager decides what to show based on the rest of the URL. So, for example, mysite.com/eventspage/locations/ or mysite.com?p=x&locations_page=1 would return a list of current locations.

There may be times where you want to override certain content generated by Events Manager either replacing it entirely, replacing parts, or adding to the default html generated. If we use the wordpress filters em_content and em_content_pre, we can intercept the output process and add what we need.

This tutorial provides a brief explanation of these two filters, they are covered in more depth on our tutorial page, creating a custom event information page.

em_content_pre

This filter is best used if you want to prevent Events Manager from trying to output content altogether. In some cases you may want to add your own custom pages, and therefore it would make sense to check for this first before EM goes and does unnecessary work.

This works pretty much exactly like em_content, except a second parameter is passed to your function, which is the original content of the wordpress page that will be overwritten by Events Manager. To find out how to use em_content_pre, see our tutorial page, which makes use of this filter when building an example add-on for Events Manager.

em_content

If you need to add certain content to event pages, or do further processing on the HTML output of Events Manager, this is the filter for you!

function my_em_custom_content($content){
if( /* Do something here to decide whether to override */ ){
$content .= "Here, I'm adding this extra text to the end of my event content.";
}
//Whatever happens, you must return the $content variable, altered or not.
return $content;
}
add_filter('em_content','my_em_custom_content');

Note that if you want to change the title text (e.g. the texts that appear in your window title bar and the title of the event), you should also hook into the em_content_page_title filter, which works exactly like the em_content filter. In fact, you only should need to change your function name (so there's no duplicates), filter name and custom content to get this to work:

function my_em_custom_content_title($content){
if( /* Do something here to decide whether to override */ ){
$content .= "My Custom Title";
}
//Whatever happens, you must return the $content variable, altered or not.
return $content;
}
add_filter('em_content_page_title','my_em_custom_content_title');