Codex tools: Log in
Contents |
Returns the post excerpt for assignment to a variable. This tag must be within The Loop.
If you only wish to print the excerpt you may prefer to use the_excerpt().
<?php $excerpt = get_the_excerpt( $deprecated ) ?>
$deprecated is not required.
get_the_excerpt() can be used to retrieve and store the value in a variable, without outputting it to the page.
<?php
$my_excerpt = get_the_excerpt();
if ( $my_excerpt != '' ) {
// Some string manipulation performed
}
echo $my_excerpt; // Outputs the processed value to the page
?>
Use get_the_excerpt() to print an excerpt by specifying a maximium number of characters.
<?php
the_excerpt_max_charlength(140);
function the_excerpt_max_charlength($charlength) {
$excerpt = get_the_excerpt();
$charlength++;
if ( mb_strlen( $excerpt ) > $charlength ) {
$subex = mb_substr( $excerpt, 0, $charlength - 5 );
$exwords = explode( ' ', $subex );
$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
if ( $excut < 0 ) {
echo mb_substr( $subex, 0, $excut );
} else {
echo $subex;
}
echo '[...]';
} else {
echo $excerpt;
}
}
?>
get_the_excerpt() is located in wp-includes/post-template.php.