Created
August 30, 2018 11:28
-
-
Save navnit-viradiya/f1f247bedc346ca2d260160c7efaf00d to your computer and use it in GitHub Desktop.
Set character limit on get_the_content() or get_the_excerpt() in wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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