-
-
Save ninnypants/1305603 to your computer and use it in GitHub Desktop.
Simple function to Change the length of an 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
<?php | |
## Truncate Post | |
function custom_excerpt_length(){ | |
global $excerpt_length; | |
return $excerpt_length; | |
} | |
function custom_excerpt_more(){ | |
global $excerpt_more; | |
return $excerpt_more; | |
} | |
function truncate_post($length = 55, $more = '[...]',$echo = true){ | |
global $excerpt_length, $excerpt_more; | |
$excerpt_length = (int)$length; | |
$excerpt_more = $more; | |
add_filter('excerpt_length', 'custom_excerpt_length'); | |
add_filter('excerpt_more', 'custom_excerpt_more'); | |
$excerpt = get_the_excerpt(); | |
remove_filter('excerpt_length', 'custom_excerpt_length'); | |
remove_filter('excerpt_more', 'custom_excerpt_more'); | |
if($echo){ | |
echo $excerpt; | |
}else{ | |
return $excerpt; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment