Tag Archives: How to limit post length in wordpress

How to limit post length on your homepage

0
Filed under Wordpress Tips

I just needed to set this up for myself so why not write a brief tuto­r­ial so I will remem­ber. I orig­i­nally found this at here

I am repeat­ing this infor­ma­tion since I often have to do the same thing on other blogs for clients and such and to fur­ther explain some points I messed up on via the original.

In essence to repeat what was said the code below will go into the functions.php of your indi­vid­ual theme. Uti­liz­ing CODA i log in to my server and open this fold­ers path: blog > wp-content > themes > your theme name >functions.php . Within functions.php , I just cre­ated a space among the other func­tions and pasted the code below and saved the file — do not close the file as you may need to return to the orig­i­nal state (note that there is a com­ment added that is dif­fer­ent form the original):


// TO LIMIT WordPress Post length on homepage
function string_limit_words($string, $word_limit)
{
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(' ', $words);
}

Now In the same folder within your them locate index.php and replace the line :

with :


< ?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,40); ?>

I orig­i­nally tried to just replace the the words : the_content with all of the other code. Now after a cou­ple of tries I slapped my head got it. Not too tough really, and it works very well.

Incom­ing search terms:

Bad Behavior has blocked 3 access attempts in the last 7 days.