If you have a theme that displays excerpts on index type pages of your site, read on. Also, if you’ve opted for using custom excerpts instead of WP’s built-in ‘more’ tag, there are a couple excerpt related plugins that will help you make the most of these features. I recommend using this plugin as opposed to the one below, for simplicity’s sake. However, if you want more control (as laid out in the parameters below) then see if this works better for you:
Advanced Excerpt Plugin
For super quick and flexible, check out the Advanced Excerpt plugin by Bas van Doren. This one can be installed by going to your Plugins>Add New menu and typing ‘advanced excerpt’. The main advantage of this plugin is that you don’t need to alter theme files and there is a settings page with a few handy options.
Remember, if you don’t like where a particular post’s excerpt is cut off, you can use the Excerpt field to create a manual excerpt. Instead of being truncated, ALL text entered in the Excerpt field will be displayed.
The Excerpt Reloaded Plugin
The rest of this article details how to install and configure The Excerpt Reloaded plugin, which is not as pluggable as the one above, but is still running solid as the original excerpt plugin and can have finer control over filtering elements out of the raw content, if need be. If the top one doesn’t fit your needs, give this one a try. You will have to edit your theme files, but that is possible through the wp-admin panel…
- Download the latest version of The Excerpt Reloaded
- Activate the_excerpt_reloaded plugin in your WordPress admin panel, under the ‘Plugins’ tab
- Replace ‘ <?php the_excerpt(); ?> ‘ or ‘ <?php the_content(); ?> ‘ with ‘ <?php the_excerpt_reloaded(); ?> ‘ in your theme files.
Customizing the_excerpt_reloaded 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); ?>
(integer) Number of words to display before ending the excerpt. Default is 120.
(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>’.
(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’.
(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.
(string) If use_more_link is set to TRUE, set this to define what text to use for the link. Default is ‘(more…)’.
(boolean) Display more link (TRUE) or not (FALSE), even when excerpt is less then excerpt_length. Defaults to FALSE.
(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.
(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.
<?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.
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.