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

  1. Create a new /magic-keywords/ folder in the /wp-content/plugins/ folder.
  2. 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)
  3. When you are done, you will have the following file(s) installed in these locations:
    /wp-content/plugins/magic-keywords/magic-keywords.php
  4. Activate the plugin in the WordPress Plugin Admin panel.
  5. 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.

Comments

17 Responses to “WordPress Plugin: Magic Keywords”

Pages:[1] 2 » Show All

  1. Response #1
    El (IP) on March 7th, 2008 at 1:01 am

    Is there anyway to resize the font and widget size so it fix on my sidebar? now it seem to be out of the alignment.

  2. Response #2
    Tyler @ Building Camelot (IP) on March 7th, 2008 at 8:52 am

    Sounds promising. I’ll have to give it a spin and see how it works.

  3. Response #3
    Missy (IP) on March 7th, 2008 at 9:38 am

    Hi—-Richard:

    I’m abit lost with the install instructions. I can’t just add this to my plugins folder, i have to create a separate one?

    I usually upload all my plugins in my plugins folder, is this one different?

    Please advise.

    Missy.

  4. Response #4
    richard on March 7th, 2008 at 4:23 pm

    @El: You probably have the Magic Keywords plugin confused with another plugin. There is no widget. This plugin does nothing more than gather the keywords for you to use as a plugin or theme developer. It does absolutely no modification to your pages at all, and displays nothing. It is completely up to you (at this early stage) to show and format the results. In fact, if you merely activate it and do nothing else, it is guaranteed to do nothing but chew up a few CPU cycles for no reason. :)

    @Missy: Yes, you can simply install the PHP file into your plugins folder. However, the new version under development consists of more than one file, and a separate folder will therefore be required. I was just being proactive and encouraging you to create the folder now in anticipation of the next release. (next release date is currently unknown)

  5. Response #5
    JHS (IP) on March 8th, 2008 at 4:10 pm

    Is this plugin compatible with the All in One SEO plugin?

  6. Response #6
    richard on March 8th, 2008 at 6:49 pm

    @JHS: Will this plugin work when the SEO plugin is installed? Yes. Will the SEO plugin work when this plugin is installed? Yes. Will the SEO plugin automatically use Magic Keywords if both plugins are activated? No, not unless uberdose (the author of the SEO plugin) adds support for Magic Keywords — which sounds like a really good idea. A future version of Magic Keywords (or another third-party plugin developer) could automatically shove Magic Keywords into the standard WP tag table (if none are already specified when saving a post/page), in which case the SEO plugin would pick them up just fine.

  7. Response #7
    RavanH (IP) on March 10th, 2008 at 1:42 pm

    Hey, interesting plugin but when you do not want to edit the theme files (i am using WP_MU with MANY themes installed) might it be possible to use your plugin to ‘pre-fill’ the Tags field when writing a new post or editing an old one? Just wondering how hard it would be to code that and if you by any chance were already planning on such a feature ;)

    On extra button below the post text area that says ‘Suggest tags’ upon which the post gets saved (not published) and the Tag field gets pre-filled (or better: appended ?) with the magic keywords…

    Just a thought :)

  8. Response #8
    richard on March 10th, 2008 at 5:02 pm

    I guess I should add it to the very long laundry list, and move it close to the top, based on feedback. It’ll probably be a month or so by the time I get around to it, though — because I’m simply swamped in the real world! (I, too, use WPMU for all our blogs, except this one)

  9. [...] Magic Keywords - gera palavras-chave para seus posts e páginas no [...]

  10. Response #10
    WordPress Plugins Database » Plugin Details » Magic Keywords (IP) on March 25th, 2008 at 8:46 pm

    [...] Visit [...]

Pages: [1] 2 » Show All

Contribute to the Conversation: