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);
I used it and working fine. Thanks.
hah i love it
I was looking for an excerpt for Magic fields’ text field in WordPress, this function works fine.
Thank you!!!