Custom Excerpt

function.php
function my_excerpt($excerpt = ”, $excerpt_length = 250, $readmore = “Continue Reading ยป”,$tags = ‘‘) {
global $post;
$string_check = explode(‘ ‘, $excerpt);

if (count($string_check, COUNT_RECURSIVE) > $excerpt_length) {
$new_excerpt_words = explode(‘ ‘, $excerpt, $excerpt_length+1);
array_pop($new_excerpt_words);
$excerpt_text = implode(‘ ‘, $new_excerpt_words);
$temp_content = strip_tags($excerpt_text, $tags);
$short_content = preg_replace(‘`\[[^\]]*\]`’,”,$temp_content);
// $short_content .= ‘…
‘guid .'” title=”‘.$post->post_title.'”>’.$readmore.’‘;
return $short_content;
}
}
Your file.php

echo my_excerpt(get_the_content(), 50);
echo my_excerpt(get_the_content(), 100);
echo my_excerpt(get_the_content(), 10);

3 thoughts on “Custom Excerpt”

Leave a Reply

Your email address will not be published. Required fields are marked *