Skip to content

Instantly share code, notes, and snippets.

@barryhughes
Created February 9, 2015 15:16
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 barryhughes/93f1d0a6a02e735d6b97 to your computer and use it in GitHub Desktop.
Save barryhughes/93f1d0a6a02e735d6b97 to your computer and use it in GitHub Desktop.
Reduces the gcal description size *after* it has been filtered by the_content (applies to TEC 3.9.x)
<?php
// ---------------------------------------------------------------------------------------
// When inserting this into a theme's functions.php file you can copy and paste everything
// below this comment (no need to include the opening "<?php" tag, etc!)
// ---------------------------------------------------------------------------------------
/**
* Shortens the event description used within Google Calendar links.
*
* The Events Calendar already truncates the event description before using it in Google
* Calendar links - however some themes/other plugins may add additional markup/content
* after this, expanding it back to too big a size to make for a valid request.
*
* @param array $properties
* @return array
*/
function truncate_gcal_description_late( array $properties ) {
$details = $properties['details'];
if ( strlen( $details ) > 996 ) {
//Strip tags
$details = strip_tags( $details );
$url = get_permalink();
$details = substr( $details, 0, 996 );
//Only add the permalink if it's shorter than 900 characters, so we don't exceed the browser's URL limits
if ( strlen( $url ) < 900 ) {
$details .= ' (View Full Event Description Here: ' . $url . ')';
}
}
$properties['details'] = $details;
return $properties;
}
add_filter( 'tribe_google_calendar_parameters', 'truncate_gcal_description_late' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment