Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
Created February 28, 2015 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leepettijohn/832827844f773604d85f to your computer and use it in GitHub Desktop.
Save leepettijohn/832827844f773604d85f to your computer and use it in GitHub Desktop.
Format content length if no excerpt is defined
add_action ('the_content','my_excerpts');
function my_excerpts($content = false) {
global $post;
// If is the home page, an archive, or search results
if(is_front_page() || is_archive() || is_search() || is_tag()) :
global $post;
$content = $post->post_excerpt;
// If an excerpt is set in the Optional Excerpt box
if($content) :
$content = apply_filters('the_excerpt', $content);
// If no excerpt is set
else :
$content = $post->post_content;
$excerpt_length = 55;
$words = explode(' ', $content, $excerpt_length + 1);
if(count($words) > $excerpt_length) :
array_pop($words);
array_push($words, '...');
$content = implode(' ', $words);
endif;
$content = '
' . $content . '
';
endif;
endif;
$morelink = '<a class="more-link alignright" href="'. get_permalink($post->ID) . '">Read Some More...</a>';
// Make sure to return the content
return $content.$morelink;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment