WordPress Plugin: Magic Keywords
The Magic Keywords plugin generates keywords for your individual blog posts and pages. Unlike most other keyword generators, the plugin also looks for two-and three-word patterns, and also groups certain words together into one by crudely checking to see if they might have the same root (e.g. Spam, spammers, spams). Works almost like magic!
Like the Plugin Output Cache, this plugin is not designed to be used by itself; you can’t just activate and expect it to do something. Rather, it is a tool to be used and integrated by plugin and theme developers, and creative blog owners.
Example Results
The following is a list of ten random articles found elsewhere on this blog, and a sampling of the respective keywords that were generated by the Magic Keywords plugin. Notice the mix of multi-word keywords such as “World Trade Center” and “banana bread” alongside very relevant single-word keywords.
- Web Design: Internet Explorer, search engine, site, web, navigation, text, design, users, look
- World Trade Center: World Trade Center, September 11, American, ceremony, forget
- Red Eye: blood vessels, iris, eye, red, close, open, light, flash, retina, red-eye, back
- Opposite Sex: best friends, one-on-one time, female, social, male, think, sex, people, women
- Wake Island: Wake Island, United States, Pan American, Marshall Islands, island, Japanese
- Citibank letter: due date, late fee, grace period, Citibank Visa, pay, statement, month, account
- Ancient History: Hanging Gardens, years later, thousand years, world, ancient, city, Babylon
- Banana Bread: Best Banana Bread, banana bread, loaf, best, Maui, Kahakuloa, road
- WordPress Theme: WordPress Theme, navigational menus, WordPress hooks, page, blog
- Adopt an Orphan: adopting Anna, Ukrainian Orphan, reward, comment, website, orphan, girl
Putting the Magic Keywords plugin up against some established literature, the following keywords were generated (excerpted):
- The Iliad (Book One): proud monarch, Grecian camp, Grecian train, god, king, heaven
- The Raven: Night’s Plutonian shore, ominous bird, Raven, chamber door, nevermore, soul
- Green Eggs and Ham: eat green eggs, Sam-I-am, ham, train, mouse, house, Sam, box, car
Requirements
In its current state of development, the fledgling Magic Keywords plugin will work on any version of WordPress later than v1.5.0, and on any version of WordPress MU. You must edit your WordPress themes and plugins to use the relevant Magic Keywords functions.
No other plugins are required for this plugin to actually do its work. But you’ll need a Magic-Keywords-enabled plugin or theme (or roll your own) in order to see any results.
Installation
- Create a new
/magic-keywords/folder in the/wp-content/plugins/folder. - Copy all of the files in the zip archive into the new
/wp-content/plugins/magic-keywords/folder. (Today there is only one file, but there are more to come soon) - When you are done, you will have the following file(s) installed in these locations:
/wp-content/plugins/magic-keywords/magic-keywords.php - Activate the plugin in the WordPress Plugin Admin panel.
- Installation complete!
Usage
I completely rewrote the Magic Keywords from scratch for the WordPress platform, having learned a lot of lessons with the older but similar MTKeywords plugin for Movable Type. There are now two template functions to return a set of keywords for use in themes and plugins.
Template Functions
Although the code for this plugin contains several callable functions, I recommend that only the following functions be used in your page templates.
The magic_keywords function returns a string containing a comma-separated list of generated keywords like the examples above. The $post variable supplied by WordPress is a required parameter. At this stage of the plugin development, the call must be made “inside the loop“. If you want a different delimiter (e.g. ‘|’ or ‘;’), for now, just edit the plugin and change the value of the $magic_key_delimiter variable. Example:
<?php echo magic_keywords($post); ?>
The get_magic_keywords function returns an array you can process or sort for use in theme or plugin development. This time, instead of passing the $post variable, you need to pass a string containing all the text you want the plugin to analyze. Then use the resulting array to do whatever you want. I’m not going to begin to try to limit your imagination as to what you can or can not do with it! Example:
$text = $post->post_title.”\n”.$post->post_content;
$keyword_array = get_magic_keywords($text);
The Long Story
The plugin is based heavily on my old Movable Type plugin called MTKeywords. Way back in 2004, I had originally created it to fill up the keywords META tag, but plugin and theme developers began to branch out and use the plugin in ways I had never imagined: automatic post tags, classification, plugin development, and lots more. A year and a half after I moved to WordPress, I abandoned the old MTKeywords plugin once Movable Type modified their table structure and the plugin became less effective.
More of the story to come soon…
Future Development
There’s a long laundry list of things to do with this plugin:
- It’s designed for English language only right now. I’m working on i18n features.
- The plugin looks only at the text you provide (or the current post). I’d like to expand it to consider already-known tags and categories.
- While it normalizes capitalization pretty well, there is need for some minor improvement.
- There are a few known cases where it will not strip trailing periods, some intentional, some not.
- A few sections of the code are redundant and should be cleaned up and consolidated.
- More configuration options. Might create an admin page if it is warranted, or just use tags.
- Some of the commented-out verbs need analysis. Add some. Look for more good stop words.
- It’s fast, but I’d like it to be faster.
- Enhance the word root detection.
- Optionally include approved comments to analyze (just like the old plugin). That feature rocked!
- Probably a dozen other things that I haven’t written down!
Revision History
| Version | Release Date | Description |
|---|---|---|
| v0.99 | 2004-10-19 | Initial release (based on Movable Type) |
| v1.xx | 2004-2006 | Several releases for Movable Type |
| v2.00 | 2008-03-03 | First release created for the WordPress platform |
This plugin is provided as-is, without any warranty of any kind, express, implied or otherwise, including without limitation, any warranty of merchantability or fitness for a particular purpose. In no event shall I be liable for any special, incidental, consequential or indirect damages of any kind, or any damages whatsoever resulting from loss of; use, data or profits, whether or not advised of the possibility of damage, and on any theory of liability, arising out of or in connection with the use or performance of this plugin.
[...] Visit [...]
[...] Visit [...]
Not sure if this is working in WP 2.5. Checked the site to see what keywords where being given on a post and .. nothing. Perhaps I need to add a bit of code somewhere in the template for it to work right?
Me, I’d start with reading the information above, especially under the Requirements and Usage sections. There is no known issue with the plugin working with WordPress v2.5.
The next version of Magic Keywords is in development and includes significant upgrades to keyword generation accuracy — those upgrades have been in testing for a couple of weeks, and have a couple more weeks of testing to go. One of the options I’m also considering before final release is to make this a more standalone plugin that will begin automatic insertion of keywords into the Tag field, but will still retain the flexibility to be used by other plugin and theme developers. That seems to be what the community is most interested in, so that’s what I’m likely to deliver.
[...] Magic Keywords Determines the best keywords for your individual blog posts and pages — works almost like magic! By Richard D. LeCour. [...]
I have to say, I love this plugin. It is perfect. I put it on every site I do now because it’s pure genius and is necessary!
Well done Richard. Well done.
[...] Magic Keywords von Richard D. LeCour erzeigt aus Texten im Blog passende Schlüsselworte, die über eine PHP Anweisung in die Templates eingebunden werden können. Bookmarks setzen: Diese Icons verlinken auf Bookmark Dienste bei denen Nutzer neue Inhalte finden und mit anderen teilen können. [...]