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 );