Posted by Dwayne on April 4, 2011 – 12:56 pm
OK. Jut had a request increase the post length of posts on the home page. I at one time needed to limit the length of of the post on Homepage. I managed that. This was similar. Found a resource here that had several options. The on ehtat worked for me was this:
Find the function.php file inside of your WP theme. If you dont know its in this directory: wp-content/themes/ here you need to choose the theme folder you are currently using. You can find out what this is by going to your WP admin page and under appearance > themes it should tell you the name of the template. The folder name “should” be similar. functions.php should be right inside there.
Now, you’ll add this all by itself :
<?php
add_filter(‘excerpt_length’, ‘my_excerpt_length’);
function my_excerpt_length($length) {
return 150; // Or whatever you want the length to be.
}?>
My post is set to 150 characters.…
Thats it. Worked like a charm.
Posted by Dwayne on July 3, 2010 – 12:04 pm
I just needed to set this up for myself so why not write a brief tutorial so I will remember. I originally found this at here
I am repeating this information since I often have to do the same thing on other blogs for clients and such and to further 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 individual theme. Utilizing CODA i log in to my server and open this folders path: blog > wp-content > themes > your theme name >functions.php . Within functions.php , I just created a space among the other functions and pasted the code below and saved the file — do not close the file as you may need to return to the original state (note that there is a comment added that is different 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 originally tried to just replace the the words : the_content with all of the other code. Now after a couple of tries I slapped my head got it. Not too tough really, and it works very well.
Incoming search terms: