WordPress | How trim text after a number of characters
This time i need to have a posts archive on which every posts have a title and a excerpt with a maximum number of characters.
The goal is cut text after a number of characters and add “…” after the trimmed text.
You can use something like this snippet :
<?php
$news_excerpt = get_the_excerpt(); // Get the excerpt
echo(substr($news_excerpt, 0, 155) . '...'); // Trim the excerpt after 155 characters
$news_title = get_the_title(); // Get the title
echo(substr($news_title, 0, 75) . '...'); // Trim the title after 75 characters
?>
You can change the number of characters every time you use it..
That’s all