I grabbed the code from here
I have this in my post right now:
"Test sentence for excerpt purposes.
Link:
https://www.ankitdesigns.com/demo/bysc/competitive/ontario-player-development-league/"
But this is what's being outputted right now:
"Test sentence for excerpt..."
This is how I'm calling it in my code: $content = get_excerpt(320, 'content');
what I don't understand is if it's set at 320
it should grab all of this content, but it's not.
Here's the excerpt function:
function get_excerpt($limit, $source = null){
if($source == "content" ? ($excerpt = get_the_content()) : ($excerpt = get_field('bio')));
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $limit);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
$excerpt = '<p>' . $excerpt . '...</p><div class="read-more"><a href="' . get_permalink($post->ID) . '" class="bysc-btn-text bysc-btn-text-primary">Read More</a></div>';
return $excerpt;
}
Why is the text being cut off early? Shouldn't it show it all?
get_excerpt()
function withadd_filter( 'excerpt_length', 'get_excerpt', 999 );
? Also, you should add a personalized prefix to the function nameget_excerpt
, i.e.darren_get_excerpt
to avoid naming collisions.add_filter
. I'm using the$content
I mentioned in my post inside my loop.strripos($excerpt, " ")
will always cut off the last word. Your function is ignoring UTF-8 characters, so it will break other things inevitably. :) See this answer for a better version.