Lexicon WordPress Plugin

 By Shamus May 24, 2006 19 comments

This is a wordpress plugin I’ve made that will find certain words – which you define – and turn them into links which lead to your dictionary. The user can mouse over the word to see a short definition, or they can follow the link to see the full definition. This is handy if you have a lot of jargon on your blog which might confuse newcomers.

Example:

According to Steven Sempai, the TV series of Read or Die differs greatly from the OVA. Meganekko agent paper is only in the OVA, and contrary to common practice, the OVA has less fan service than the TV series. There is no ecchi, and most otaku will be glad to hear there isn’t a lolicon character, either. The cast is mostly female, but this isn’t a harem comedy. Agent paper is a sort of quasi-mahou shojou who can manipulate paper to form weapons and tools. There aren’t any mecha, and while agent paper is sometimes kawaii you won’t find any slapstick chibi humor here. The Seiyuu in the series are all excellent. I thought the story was silly, but some people liked it. If you did, then akanbe!!

In the above text, I didn’t create any of the tooltops or hyperlinks, I just typed the words and the plugin handled the rest. If I edit the post, I don’t have to deal with the dense clutter required to make all of that work. Editing that paragraph in HTML would be a nightmare, but with the plugin I just edit the plain text and the links happen as if by magic.

Installation:

Note that this plugin requires PHP5. If your webserver does not have this, the plugin won’t work!

First, download the plugin here. Unzip the files. You’ll need to edit lexicon.php (just a bit!) and then make your dictionary.

This plugin isn’t very advanced, and requires a little more setup than most plugins to get it working right. Deep breath, you can do it.

  1. Create the dictionary
    The first step is to create the dictionary file you will use, which is called dictionary.txt by default. You can see my dictionary here. There is an example dictionary included in the zip as well.

    For each word in your dictionary, there are 4 lines, the last of which is optional. Line 1 is the word (or even phrase) itself. Line 2 is a short definition that will be used as a tooltip. Line 3 is the full definition. Line 4 is optional, and can specify an image to use for the dictionary entry. Then you must have at least one blank line, and then the process starts over with line 1 of the next word, until the end of the file is reached. If you omit the last line (the image) then the entry just won’t have one. No biggie.

    For each entry in the dictionarty there are several lines:

    • Line 1 is the word itself.
    • Line 2 is the short definition used as a tooltip when the mouse hovers over the word
    • Line 3 is the full definition. Remember, it all has to be on one line!
    • Line 4 is the “see also”. Just put words seperated by commas and the dictionary will use them to cross-reference. Leave a BLANK LINE if you don’t want this.
    • Line 5 is the image, including path. Leave a BLANK LINE if you don’t want an image
    • Leave one more BLANK LINE before you list the next entry.

Note that you don’t need to sort the entries. The plugin will sort them into alphabetical order for you.

Note that if the word in your dictionary is defined in ALL CAPS, then it is treated as an acronym, and it will only turn into a link if it is written in all caps. If you do not define the word in all uppercase, it will be treated normally and any case combination of that word will become a dictionary link.

  • Add the dictionary to at least one post on your blog

    Make a new post. In this post add the following text:

    :LEXICON:

    That is a colon, the word “LEXICON” in all caps, and then another colon. The plugin will replace this word with the contents of your entire dictionary, complete with links and images. You can see mine here.

    Now edit the lexicon.php. If you don’t know PHP this might be a little scary. Be brave. Just a few lines down you’ll see:

    $ad_dictionary_url = "www.example.net/somepage";

    This is where you tell the plugin how to find your dictionary. Inside of the quotes, put the address of the entry you just created. If the permalink to that post is www.myblog.com/wordpress/my-dictionary/ then change the line to say:

    $ad_dictionary_url = "www.myblog.com/wordpress/my-dictionary/";

  • Place lexicon.php and dictionary.txt into your wordpress /plugins directory

  • Enable the plugin in the wordpress control panel

  • All done! Any of the words that appear in your dictionary will become links. You can add or change the contents of the dictionary at any time.

    Using Lexicon

    Dictionary words which appear inside of HTML tags are ignored. Words appearing after a < and before a < are assumed to be an HTML tag and the plugin won’t mess with them.

    If you do NOT want a word to become a dictionary link, preceed the word with a percent symbol. For example:

    Sempai!
    %Sempai!
    

    Would yield:

    Sempai!
    %Sempai!

    Note that you should do this if the word appears within a link! If you don’t, the plugin will still turn the word into a dictionary link, which will break the link you were trying to create and make a mess of the HTML.

    19Just 19 comments.


    1. ubu roi says:

      Do you know if it will work on 1.5.2? If you have no idea, I volunteer to be the guinea pig though (depending on how some other things fall out) I may not get to it until after the holiday.

    2. Shamus says:

      I don’t know about 1.5 compatability.

      Good luck. :)

    3. impressive work Shamus. Truly you have mighty code-fu!

      For a while I’ve been looking for a blog-wiki hybrid. The closest I’ve seen is Jotspot but thats a paid service. I think that your plugin is a good halfway point, though a true combination would really represent something revolutionary.

      Perhaps some Wiki protocols would help Lexison, though – for example, you could require that the dictionary terms be surrounded by bracket chars, ie [otaku] would get picked up but not Otaku, otaku, etc. Also, the text within the brackets could be used for the link anchor, so you would avoid the case-replacement issue. You could also use an invisible HTML char instead of the brackets, like ampersand-nbsp.

    4. Shamus says:

      I wish I had known about the brackets. That is even easier than the blind find & replace, and it eliminates nearly all of the drawbacks I mention above. It also avoids the problem of false positives, like picking up the end of “hotaku”, if it was a word.

      It’s clearly the right way to go. I’ll probably update it soon. I should probably look into the wiki markup and see if it has any other useful conventions.

    5. actually, what if you could use a real wiki as your parsing engine? ie take an existing wiki platform and make your plugin harness that for the link organization?

      Here are some similar plugins that add Wiki functionality:

      http://www.andrewsw.com/wiki/moin.cgi/WP-Wikify
      this one seems to use WP Pages as the targets.

      http://floatingsun.net/blog/tags/wp-dokuwiki/
      Thsi one seems to actually be a crossover with DocuWiki.

    6. Are you still working on this plugin?
      I get this error when I activate it :(
      I am running WordPress 1.5.1.2
      What am I doing wrong?
      Help me please!

    7. Interesting. There are some good ideass presented here. I need to do spend some time reading more about these topics.

    8. dizi izle says:

      Are you still working on this plugin?

    9. gaelle says:

      I am running Wp 2.5 and was quite interested in your plugin as IMM glossary is not 2.5 compatible. Your plugin works perfectly but generates quite a number of validation errors because of tables. Is there a way to get the same plugin xhtml 1 transitional compliant ? I am desperatly trying to find a simple plugin(lexicon, dictionary or glossary) working on Wp 2.5…awkward task.

    10. cyd says:

      Is there a version for 2.8 planned ? thanks.

    11. Elgun says:

      Hi.
      I am really interested in this plug in. I want to know something. What I need is to create SEO terms dictionary from English into my native.

      Does it have a widget so I can add sidebar. My users need to type english word and get Azerbaijani translation.

      Is there a way to this with your plug in?

      Thanks

    12. tatil says:

      Twenty Sided » Blog Archive » Lexicon WordPress Plugin very best information thank you.

    13. Some Hume says:

      Do you still have the source code for this? I’d like to try to get it working with the new version of WP.

    14. David S says:

      Hi Shamus, I appreciate the time you’ve taken to write this plugin.

      But I wonder why you are showcasing the plugin when it has certain bugs and you won’t even use it as a demo on your site because of such bugs.

      I’d be interested to know when you fix those bugs. I haven’t yet found a plugin that has all the integrated features you have here.

      Thanks,
      David

    15. mcgurker says:

      It’s pretty likely that you’ll never see this, but I’d like to ask why this is no longer a thing on the blog? It seems like it’d still be helpful to you. I’m guessing it’s a compatibility thing, but what do I know?

    16. mcgurker says:

      Sorry for the double post.

    17. Xsqpcfzi says:

      What do you want to do when you’ve finished? Child Models 887

    18. UGG 5340 Ultimate Tall Boots is so comfortable and charm, if you try on them,you will love them immediately,and we are making the discount at the time.The fashionable and charm UGG 5359 Women’s Nightfall Boots is cheap on sale ,you can get them at a very low price,it really very cost-effective,come on.

    19. Hannah says:

      What do you do? viagra for men price in kolkata The primary matching values used to determine which claim is being canceled are the