How to Customize WordPress Excerpts

If you’ve opted for using custom excerpts instead of WP’s built-in ‘more’ tag, The Excerpt Reloaded plugin can’t be beat for it’s ease of use and versatility. The following article details how to install and configure The Excerpt Reloaded plugin.

  1. Download the latest version of The Excerpt Reloaded
  2. Unzip the file and upload it to your ../wp-content/plugins/ folder
  3. Activate the_excerpt_reloaded plugin in your WordPress admin panel, under the ‘Plugins’ tab
  4. Replace ‘ <?php the_excerpt(); ?> ‘ or ‘ <?php the_content(); ?> ‘ with ‘ <?php the_excerpt_reloaded(); ?> ‘

Customizing Excerpts

The Excerpt Reloaded has the following parameters that can be used to fine tune excerpts:

<?php the_excerpt_reloaded(excerpt_length, 'allowedtags', 'filter_type', use_more_link, 'more_link_text', force_more_link, fakeit, fix_tags); ?>

Parameters:

excerpt_length
(integer) Number of words to display before ending the excerpt. Default is 120.

allowedtags
(string) Defines which HTML tags to retain in excerpt. Use the format ‘<img>’. For multiple tags, enter as single string: ‘<a><img>’. Default is ‘<a>’.

filter_type
(string) Defines how WordPress should filter/format an excerpt’s content. Options are based on content/excerpt tags: ‘content’, ‘content_rss’, ‘excerpt’, ‘excerpt_rss’. Set to ‘none’ to display raw content. Default is ‘excerpt’.

use_more_link
(boolean) Should the “more” link be displayed (TRUE) or not (FALSE). If set to false, function displays ellipsis (…) if content more than that displayed; neither link nor ellipsis displays if output is less than excerpt_length; Defaults to TRUE.

more_link_text
(string) If use_more_link is set to TRUE, set this to define what text to use for the link. Default is ‘(more…)‘.

force_more_link
(boolean) Display more link (TRUE) or not (FALSE), even when excerpt is less then excerpt_length. Defaults to FALSE.

fakeit
(integer) Use content as excerpt (1) or not (0) if excerpt is empty. Set to 2 to force content as excerpt under all conditions. Defaults to 1.

fix_tags
(boolean) “Repair” HTML tag elements (TRUE) or don’t (FALSE). This is implemented to deal with improperly closed tags which may be caused by excerpt_length. If fix_tags is set to FALSE, the plugin will not attempt XHTML validation and repair on improperly closed tags (due to excerpt_length breaking them in mid-element). Defaults to TRUE.

Example:

<?php the_excerpt_reloaded(23, '<img><a>', 'content', true, 'Read More...', true);?>

This would give us excerpts 23-words long, allow images and links to render when seen in excerpts, use post ‘content’ to generate.excerpts, use the ‘more’ link, more link text (in this case it’s ‘Read More…’), that we should always see the ‘Read More…’ link, and finally, that any incomplete tags in the ‘more’ text should be fixed.

Optional Excerpt

Using either the default <?php the_excerpt(); ?> or the Excerpt Reloaded tag <?php the_excerpt_reloaded();?> you can also make use of the ‘optional excerpt’ field if you would rather provide a custom excerpt.

When writing or editing a post you can fill in the ‘optional excerpt’ field and this text will be displayed on all your theme pages that use excerpt tags, rather than the excerpt being taken from the full content. This way you can provide custom previews of protected articles and completely secure the actual article. And if you don’t feel like filling in ‘optional excerpt’ it will simply use the content to generate an excerpt.