Skip to content

Instantly share code, notes, and snippets.

@aalimran07
Created June 24, 2018 03:24
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 aalimran07/99e17337dfdca9d28d0c83f84379f36f to your computer and use it in GitHub Desktop.
Save aalimran07/99e17337dfdca9d28d0c83f84379f36f to your computer and use it in GitHub Desktop.
function loanplus_get_excerpt($limit, $source = null){
if($source == "content" ? ($excerpt = get_the_content()) : ($excerpt = get_the_excerpt()));
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $limit);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
return $excerpt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment