WordPress : the_excerpt()

Posted by

Usage Advanced Excerpt Plug-in


<?php the_excerpt(); ?> 


This tag has no parameters.


Advanced Excerpt


Default Usage

Displays the post excerpt. Used on non-single/non-permalink posts as a replacement for the_content() to force excerpts to show within The Loop.

<?php the_excerpt(); ?>

Use with Conditional Tags

Replaces the_content() tag with the_excerpt() when on archive (tested by is_archive() ) or category (tested byis_category() ) pages.

Both the examples below work for versions 1.5 and above.

<?php if ( is_category() || is_archive() ) {
} else {
} ?>

Control Excerpt Length using Filters

By default, excerpt length is set to 55 words. 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

By default, excerpt more string at the end is set to ‘[…]’. To change excerpt more string using excerpt_more filter, add the following code to functions.php file in your theme:

function new_excerpt_more($more) {
	return '[.....]';
add_filter('excerpt_more', 'new_excerpt_more');


Make the “read more” link to the post

Place this in a theme’s functions.php to make the “read more” link to the post

function new_excerpt_more($more) {
       global $post;
	return '<a href="'. get_permalink($post->ID) . '">Read the Rest...</a>';
add_filter('excerpt_more', 'new_excerpt_more');