Troy Chaplin  /  Design & Development

Inspiration for the Creative Mind

Blogging about design, development, games and other related topics

Setting a Consistent Custom Excerpt Function for WordPress 2.9 or Higher

Depending on how you have designed the overall look and feel of your site, you may want to use more or less than the 55 characters that the default WordPress the_excerpt template tags uses. By default, excerpts will also appended [...] at the end to indicate to readers that the text continues, which can also be controlled in the same manner that we do the excerpt length.

Change the Excerpt Length

By inserting the following piece of code into your functions.php file , you can specify the exact amount of characters you wish to have output by changing the number of characters currently indicated as 50:


function new_excerpt_length($length) {
return 50;
}
add_filter('excerpt_length', 'new_excerpt_length');

Edit the Excerpt Read More Link

By inserting the following piece of code into your functions.php file, you can control the text and formatting of the excerpts read more link. This example has the excerpt end with … then closes the paragraph tag, then adds the permalink to the post inside an H2 tag and links the READ-MORE-TEXT, which should be changed to fit your needs.


function new_excerpt_more($more) {
return '...</p>
<h2><a href="'.get_permalink().'">READ-MORE-TEXT</a></h2>

';
}
add_filter('excerpt_more', 'new_excerpt_more');

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>