Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Set character limit on get_the_content() or get_the_excerpt() in wordpress
function break_content($text,$length){
$text = trim($text);
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);
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