Custom Excerpt Placeholder for Events Manager

This PHP snippet creates a #_CUSTOMEXCERPT placeholder to be used with the Events Manager plugin. Just throw it in functions.php, and you can then use #_CUSTOMEXCERPT in place of #_EVENTEXCERPT in your event/list templates.

The snippet has two variables you may wish to edit:

  • $strip_HTML – whether or not to remove HTML tags from the custom excerpt. Be careful if setting this to false, as this can cut off in the middle of your tag attributes (e.g., <img src=”/wp-content/uploa” />)
  • $length – the length of your custom excerpt (characters)
/** Create custom #_CUSTOMEXCERPT placeholder for Events Manager */
function my_em_styles_placeholders( $replace, $EM_Event, $result ) {
	global $wp_query, $wp_rewrite;

	// Whether or not to strip HTML, if not be careful with the $length as you can cut off in the middle of tags
	$strip_HTML = true;

	// Max length of the excerpt (characters)
	$length = 120;

	// String to append to excerpt, if it is longer than the max length
	$after = "…";

	switch( $result ) {
		case '#_CUSTOMEXCERPT': // name of the placeholder
			// Get standard excerpt output
			$replace = $EM_Event->output( "#_EVENTEXCERPT" );

			// Strip all HTML
			if ( $strip_HTML ) {
				$replace = strip_tags( $replace );
			}

			// Only modify the excerpt if it exceeds the maximum allowed length
			if ( strlen( $replace ) > $length ) {
				$replace = substr( $replace, 0, $length );
				$replace .= $after;
			}

			// Balance tags just in case
			$replace = force_balance_tags( $replace );

			break; // end the case
	}

	return $replace ; //output the placeholder
}
add_filter( 'em_event_output_placeholder','my_em_styles_placeholders', 1, 3 );

5 thoughts on “Custom Excerpt Placeholder for Events Manager”

    1. Thanks for making such a great plugin, Marcus! We use it to take our class registrations on this very site, and we are quite enamored of it. Good work!

    1. Sure thing, you would just have to adjust the subsequent parsing logic that follows (e.g. break the string up by spaces, and then grab however many words you want).

  1. Hey! Thanks for this post. I think this is just what I need.
    I have a quick question though… (note: PHP newbie here) Here’s my website – thefullquiver.com. If you look at the home page and look at the box that says “Upcoming Events” I want the external links in the event excerpt to be clickable in the list format (home page and Events page). Right now I’m using the placeholder #_EVENTEXCERPT{5,…}. How can I keep everything the same as it is now (using the code you provided), but make the external links (ex. facebook) clickable/hyperlinked?
    Your help is greatly appreciated! Thank you.

Leave a Comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: