Last active
December 12, 2015 08:59
-
-
Save geilt/4748326 to your computer and use it in GitHub Desktop.
Better Excerpt functionality for Wordpress. Just paste functions.php in Wordpress to use.
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
/** | |
* Excerpt by Alexander Conroy | |
* Copyright 2012 Esotech Inc. | |
* MIT License | |
* http://opensource.org/licenses/MIT | |
*/ | |
<?php | |
if(!function_exists( 'excerpt' ) ): | |
function excerpt( $size = '165', $content = NULL, $echo = TRUE, $ellipsis = TRUE, $wrap = TRUE ) { | |
if(!$content): | |
$content = get_the_content(); | |
endif; | |
$content = apply_filters( 'the_content', $content ); | |
$content = str_replace( ']]>', ']]>', $content ); | |
$content = strip_tags( $content ); | |
$content = ltrim( $content); | |
if(strlen($content) > $size): | |
$space = strpos( $content, " ", $size); | |
endif; | |
if($space): | |
$content = substr( $content, 0, $space ); | |
endif; | |
if($ellipsis): | |
$content = $content . "..."; | |
endif; | |
if($wrap): | |
$content = '<p>' . $content . '</p>'; | |
endif; | |
if( $echo ): | |
echo $content; | |
else: | |
return $content; | |
endif; | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment