WP Snapshot — A multi‐use Wordpress Plugin for Getting a Snippet of Text
Use WP Snapshot to auto-generate meta-descriptions, post summaries, page summaries and more. If you’re tired of manually writing your meta descriptions or post excerpts and want an easy way to grab a snippet of text to use on your Archive pages, then this plugin is the time-saver you’re looking for.
With redundant content checks, WP Snapshot will search your content and return the most relevant snippet of text to use as your meta-description, post summary (like in the sidebar on this site), post teaser, etc. It even has built-in defaults in case it can’t find applicable content.
What’s more, it’s fully customizable, allowing you to determine the text to use, the word limit, and the trailing text.
Installation
- Download the "mish_wp_snapshot.zip" folder, then extract.
- Upload the uncompressed folder to your plugin directory (wp-content/plugins).
- Activate the plugin through your Admin Dashboard.
Parameters
The plugin accepts 3 parameters; the custom text, the word limit, and the trailing text. Each parameter has to be set in order. See exmples for further information.
Content: The default usage is to find the relevant text to summarize by first checking for any custom text entered during installation, then checking for the post or page content, and finally—if it can’t find anything—resorting to built-in default text.
Word Limit: The default word limit is 27 words.
Trailing Text: The default trailing text is an ellipsis (…) because that indicates a trailing thought or edited text.
Usage
To call within your template, place the following code wherever you’d like the snapshot to appear.
<?php mish_wp_snapshot(); ?>
Example 1
Using the default on an Archive Page (Category, Author, Date-based, Tag, etc). Place the following within the LOOP in your template’s "archive.php" file:
<?php mish_wp_snapshot(get_the_content()); ?>
This will return something that looks like:
Here’s a quick function to determine whether or not the viewer is on the last page of a paginated post. It's useful if you want to display…
Example 2
Expanding on Example 1: Place the follwing within the LOOP on an Archive Page:
<?php mish_wp_snapshot(get_the_content(),'30', ' [more]'); ?>
This will return something that looks like:
Here’s a quick function to determine whether or not the viewer is on the last page of a paginated post. It's useful if you want to display information such as [more]
Notice how the post sumamry has been extended to add additional words, as well as replaced the ellipsis (…) with "[more]".
Example 3
The default usage as the meta-description on any page. Place this code in your "header.php" file:
<meta name="description" content="<?php mish_wp_snapshot('meta-desc'); ?>" />
WP Snapshot intuitively looks through the content of the post or page to find the appropriate text —based on the type of Page (is_category(), is_month(), is_single(), etc.)—to use for the meta-description.
Note: You must set the custom content parameter to "meta-desc" in order to use it as your meta description.
<meta name="description" content="A quick function to determine whether or not the viewer is on the last page of a paginated post. It's useful if you want to display information" />
Notice how the trailing text has been removed and the snippet of text is different than that displayed in the LOOP. This is because WP Snapshot first looks for a post excerpt to use as a meta description. If it can’t find that, it grabs the first 27 words of the post content. If that is blank (as is the case sometimes when using Pages), it grabs the title of the Page as the absolute default text.
Updates
Current Version: 0.5
Changelog:
- v0.5 : December 8, 2008 : Initial release
Conclusion
I hope this comes in handy for someone when developing a theme or just for learning purposes. Whenever I develop a script, I intentionally try to break it, so I can spot areas of improvement. If you see any, feel free to let me know!
Reader Comments
→ Skip to Comment Form
hi. Thanks for plugin
perfect.
Regards
is this application supported by wordpress 2.8?
@guerremdq: Yep, I’m using it on this site and I’m running WP 2.8.