Enhance WordPress Excerpt by Simple Functions

WordPress Excerpt is a great option needed on every theme. To Add Excerpt you can write a short summary of your post for the Excerpt field. If you choose not to write a separate excerpt, WordPress will automatically create an excerpt by truncating the first part of your post to 55 words. If you want to change the excerpt length and Remove […] string, you can use the following codes.

Control Excerpt Length using Filters

To change excerpt length using excerpt_length filter, add the following code to functions.php file in your theme:
function new_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');

Remove […] string using Filters

Only in version 2.9 and higher of WordPress
add also the following code to functions.php file in your theme:
function new_excerpt_more($more) {
return '[.....]';
}
add_filter('excerpt_more', 'new_excerpt_more');

Add “read more” link to the post

function new_excerpt_more($more) {
global $post;
return 'Read more...';
}
add_filter('excerpt_more', 'new_excerpt_more');

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.