WordPress has always made me scratch my head when it came to the excerpt. I mean, its great to be able to insert your “the_excerpt();” php code into your loop and have everything show up all nice.
The default excerpt comes out at 55 characters. That seems alright to me for a list of your blogs. If you want to change the length, that isn’t a problem. You can go right into the function.php file and make your changes. The more difficult part comes when you want to have a different length, lets say, for the sidebar. I’m sure there is a way to do this but it would take yet, more code.
The solution I found, that makes life very easy, is a little bit of code you can throw into your functions.php file. The great part here is that your regular excerpt work but now you have a whole new slew of code to pick for your excerpt.
Click the link below to use the code.
LINK: http://pastebin.com/aUZuQrZy
(Grab the code from the “RAW Paste Data” so that you don’t cary over any of the extra info.)
The functions are simple
// inside the loop
my_excerpt(); // just a regular WordPress excerpt (55 words)
my_excerpt(30); // 30 words with formatting (
this is an excerpt … […]
)
get_my_excerpt(30); // 30 words without formatting (this is an excerpt … […])
// outside the loop
// pass a Post ID to the function (required outside the loop)
my_excerpt(30, 22); // 30 word excerpt of Post with ID 22
get_my_excerpt(30, 22); // 30 word excerpt of Post with ID 22
The functions both have two argument you can use
my_excerpt($excerpt_length, $Post_id);
These functions affect also the manual excerpt. That’s why they strip all html tags from the excerpt content. Otherwhise it might break your site