Created
February 28, 2015 17:47
-
-
Save leepettijohn/832827844f773604d85f to your computer and use it in GitHub Desktop.
Format content length if no excerpt is defined
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
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