Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Created March 17, 2021 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrasguseo/68fd83a3d5504a096cc1ec849901017a to your computer and use it in GitHub Desktop.
Save andrasguseo/68fd83a3d5504a096cc1ec849901017a to your computer and use it in GitHub Desktop.
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