This function controls the maximum amount of characters displayed for an entry on the main page. If the set limit is surpassed, the text on the entry will be chopped to that amount of characters, otherwise the content will be showed unchanged.

Add following code to functions.php in your theme folder

function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
// remove  shortcode
$content = preg_replace("/\/", '', $content);
// short codes are applied

$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content);

if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = substr($content, 0, $espacio);
$content = $content;
echo "<p>";
echo $content;
echo "...";
echo "</p>";
else {
echo "<p>";
echo $content;
echo "</p>";

usage :
add this code


inside WordPress loop. This function usually replace


credits: this function from Limit Posts plugin  (the original plugin author site seems down at the moment). I have updated code above  to remove Image Caption for showing


Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: