Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
Last active August 29, 2015 14:20
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 everaldomatias/71f1b1d5f7c653bfc239 to your computer and use it in GitHub Desktop.
Save everaldomatias/71f1b1d5f7c653bfc239 to your computer and use it in GitHub Desktop.
Função WordPress para gerar resumos com limite de caracteres
/**
* Function get_excerpt
*
* @since 0.1
*
* @param string $content with text to excerpt.
* @param string $limit number of the limit.
* @param string $after with element to print in end excerpt.
*
* @return string
*/
function get_excerpt( $content = '', $limit = '', $after = '' ){
if ( $limit ) {
$l = $limit;
} else {
$l = '140';
}
if ( $content ) {
$excerpt = $content;
} else {
$excerpt = get_the_content();
}
$excerpt = preg_replace( " (\[.*?\])",'',$excerpt );
$excerpt = strip_shortcodes( $excerpt );
$excerpt = strip_tags( $excerpt );
$excerpt = substr( $excerpt, 0, $l );
$excerpt = substr( $excerpt, 0, strripos($excerpt, " " ) );
$excerpt = trim( preg_replace( '/\s+/', ' ', $excerpt ) );
if ( $after ) {
$a = $after;
} else {
$a = '...';
}
$excerpt = $excerpt . $a;
return $excerpt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment