Skip to content

Instantly share code, notes, and snippets.

@spencejs
Created March 22, 2013 04:46
Show Gist options
  • Select an option

  • Save spencejs/5218990 to your computer and use it in GitHub Desktop.

Select an option

Save spencejs/5218990 to your computer and use it in GitHub Desktop.
Customizable Additional Excerpt In Wordpress ( USAGE: limit_content( $length, $allow-tags, '$tags-to-allow' ) )
//Custom Additional Excerpt Length
function custom_excerpt($content_length = 250, $allowtags = true, $allowedtags = '') {
global $post;
$exc = $post->post_excerpt;
if ($exc == '') {
$content = $post->post_content;
} else {
$content = $post->post_excerpt;
}
$content = apply_filters('the_content', $content);
if (!$allowtags){
$allowedtags .= '<style>';
$content = strip_tags($content, $allowedtags);
}
$wordarray = explode(' ', $content, $content_length + 1);
if(count($wordarray) > $content_length) {
array_pop($wordarray);
array_push($wordarray, '');
$content = implode(' ', $wordarray);
$content .= "</p>";
}
echo $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment