Created
January 8, 2015 10:32
-
-
Save danyeah/fddbb97ad508c7faab6c to your computer and use it in GitHub Desktop.
Wordpress custom excerpt
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
/* ========================================================================== | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!
Just need removing one bracket on 37 after false.
Nice work