Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set character limit on get_the_content() or get_the_excerpt() in wordpress
<?php
function break_content($text,$length){
$text = trim($text);
if(strlen($text)<$length+10)
return $text;//don't cut if too short
$break_pos = strpos($text, ' ', $length);//find next space after desired length
$visible = substr($text, 0, $break_pos);
if(is_front_page()){
return balanceTags($visible) .'<a class="aerrow-link" href="' . get_permalink( get_page_by_path( 'testimonials' ) ).'#'. basename(get_permalink()). '"> ...Read More</a>';
}
}
echo break_content(get_the_content(),150);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment