Skip to content

Instantly share code, notes, and snippets.

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 nicdford/6f7c36c3cf4e6f401768 to your computer and use it in GitHub Desktop.
Save nicdford/6f7c36c3cf4e6f401768 to your computer and use it in GitHub Desktop.
Make shift the_excerpt replacement for Wordpress & Pods templating
function trim_content( $post_content, $length ) {
if (strlen($post_content) > $length) { // check to make sure your content is longer than what you want to display
$post_content = wordwrap($post_content, $length, "<br /><br />"); // Set br's to trim the content to the nearest whole word
$post_content = substr($post_content, 0, strpos($post_content, "<br /><br />")); // trim content
$post_content = strip_shortcodes( $post_content ); // strip shortcodes for wordpress content with shortcodes
return $post_content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment