Created
March 17, 2021 11:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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