Skip to content

Instantly share code, notes, and snippets.

@ninnypants
Forked from whyisjake/js_excerpt
Created October 22, 2011 04:03
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 ninnypants/1305603 to your computer and use it in GitHub Desktop.
Save ninnypants/1305603 to your computer and use it in GitHub Desktop.
Simple function to Change the length of an excerpt.
<?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