Last active
August 29, 2015 14:20
-
-
Save everaldomatias/71f1b1d5f7c653bfc239 to your computer and use it in GitHub Desktop.
Função WordPress para gerar resumos com limite de caracteres
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
/** | |
* 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