Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TEC > Trim the event description in the iCal export feed if it is too long
<?php
/*
* Description: Trim the event description in the iCal export feed if it is too long.
* Usage: Paste the below snippet into your active (child) theme's functions.php file
*
* Plugin: The Events Calendar
* Author: Andras Guseo
* Last updated: 2021-03-17
*/
add_filter( 'tribe_ical_feed_item', 'tec_exclude_url_from_ical_feed', 10, 2 ) ;
function tec_exclude_url_from_ical_feed( $item, $event_post ) {
// If description is longer than this many characters, then trim it
$max_char_length = 50;
// The number or words to leave is description is too long
$num_words = 10;
// Put this character / string at the end of the trimmed description
$more = "…";
if ( strlen( $item['DESCRIPTION'] ) > $max_char_length ) {
$item['DESCRIPTION'] = wp_trim_words( $item['DESCRIPTION'], $num_words, $more );
}
return $item;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment