Advanced Excerpt
This plugin adds several improvements to WordPress’ default way of creating excerpts.
- It can keep HTML markup in the excerpt (and you get to choose which tags are included)
- It trims the excerpt to a given length using either character count or word count
- You can customise the excerpt length and the ellipsis character that will be used when trimming
- The excerpt length is real (ie. “words” and characters belonging to HTML tags are not counted)
In addition to keeping HTML markup in the excerpt, the plugin also corrects HTML that might have been broken due to the trimming process.
Installation
After you’ve downloaded and extracted the files:
- Upload the complete
advanced-excerptfolder to the/wp-content/plugins/directory - Activate the plugin through the ‘Plugins’ menu in WordPress
- Go to ‘Excerpt’ under the ‘Options’ tab and configure the plugin
Frequently Asked Questions
Why do I need this plugin?
The default excerpt created by WordPress removes all HTML. If your theme uses the_excerpt() to view excerpts, they might look weird because of this (e.g. smilies are removed, lists are flattened, etc.) This plugin fixes that and also gives you more control over excerpts.
Does it work for WordPress version x.x.x?
I haven’t had the chance to test the plugin on many versions of WordPress. It has been tested on 2.2 through 2.5.1, but it might work on other versions, too. You can safely try it yourself, because the plugin is unlikely to break anything (it’s only an output filter). Please let me know if you succesfully tested it on another version of WordPress.
Can I manually call the filter in my WP templates, for example?
The plugin automatically hooks on the_excerpt() function and uses the parameters specified in the options panel. You can also call it manually and specify custom parameters. This can be useful for theme developers.
The following code is used to call the plugin’s filter function:
$advancedexcerpt->filter($text, $length, $use_words, $ellipsis, $allowed_tags)
$textis the full text of whatever you need an excerpt of.$lengthis an integer specifying the length of the excerpt.$use_words, when1tells the filter to count words instead of characters.$ellipsisis a string which is appended to the excerpt. Use HTML entities for special characters.$allowed_tagsis an array of tags that are kept in the excerpt, for examplearray('a', 'strong', 'div')
Passing null to any of these parameters (except for the first) results in the default value being used instead. This way you can change the ellipsis without changing the length, for example.
License
This plugin is licensed under the GNU General Public License. Refer to the included COPYING file for more details.