Skip to content

Instantly share code, notes, and snippets.

@danyeah
Created January 8, 2015 10:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danyeah/fddbb97ad508c7faab6c to your computer and use it in GitHub Desktop.
Save danyeah/fddbb97ad508c7faab6c to your computer and use it in GitHub Desktop.
Wordpress custom excerpt
/* ==========================================================================
13 - Excerpt custom lenght : ground_excerpt( 100, __('Read more', 'ground'), '...', 'classname' );
* ========================================================================== */
// Summary or description of a post with custom lenght
$word = __('Read more', 'ground');
function ground_excerpt( $character_length = 100, $word, $continue = '...', $class="button" ) {
global $post;
$excerpt = get_the_excerpt();
$character_length++;
if ( mb_strlen( $excerpt ) > $character_length ) {
$subex = mb_substr( $excerpt, 0, $character_length - 5 );
$exwords = explode( ' ', $subex );
$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
if ( $excut < 0 ) {
echo mb_substr( $subex, 0, $excut );
} else {
echo $subex;
}
echo $continue;
if ( !empty($word) ) {
echo ' <a href="' . get_permalink( $post->ID ) . '" class="' . $class . '" title="' . $word . ' ' . get_the_title( $post->ID ) . '">' . $word . '</a>';
} elseif ( $word === false )) {
return;
}
} else {
echo $excerpt;
}
}
@dompl
Copy link

dompl commented Sep 9, 2015

Thanks!

Just need removing one bracket on 37 after false.

Nice work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment