WordPress php Tricks – shorten the excerpt length of a blog

I won’t take too much time cause you need to cut down on the default WordPress blogĀ  excerpt length.

It’s too long and you want to reduce the excerpt words up to 20 words (or less).

Just add this code to the functions.php file in your wordpress theme file directory.

Here you go Ninjas.



function custom_excerpt_length( $length ) {
	return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );


//or you can make it long but that's a bit annoying.


function custom_excerpt_length( $length ) {
	return 500;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );



Also If you want to get rid of that wordpress blog ellipsis […] from the end of the blog excerpts, you can change customize that as well
You can change to whatever clever word you want use like read more, more info, learn more, or just the …
Just add this to the functions.php file.



function new_excerpt_more( $more ) {
	return '...read more';
}
add_filter('excerpt_more', 'new_excerpt_more');

//You can also add classes to pimp out the style so it's looks 
//nicer or make the read more font stand out or italic.
//I tend to use ninja on my classes I'm a ninja in Seattle.

function new_excerpt_more( $more ) {
	return '<span class="pimp-out-this-text">...read more</span>';
}
add_filter('excerpt_more', 'new_excerpt_more');

Its usually on base or free wordpress themes but sometimes, you’ll see it on custom websites.

wordpress_ellipsis

wordpress_readmore_excerpt