I’ve had a snippet of jQuery and javascript kicking around for a while, that I have found handy in the past for generating post slugs. Finally I’ve packaged it as a plugin to share: jQuery Slug Plugin.

This is my first jQuery plugin, so it doesn’t follow the more advanced plugin development pattern by Mike Alsup, instead I followed a more rudimentary plugin authoring tutorial.

Here’s an explanation of the plugin, and examples of its usage.

If you like this post, consider subscribing to my RSS feed.

3 Responses to “jQuery Slug Plugin”

  1. Karl Says:

    That’s a nice little plugin you’re putting together.

    One way you might be able to avoid the hyphens piling up when spaces are repeated is to modify the regex slightly:

    var slugcontent_hyphens = slugcontent.replace(/\s+/g,'-');

    Keep up the good work!

  2. Perry Says:

    Thanks for the improved regex, Karl! I’ll add that and a few other improvements to the next release.

  3. veena Says:

    I take your jquery plugin and combined it with urlify function from Django (BSD Licence) framework generated admin. You can take it and improve. Here it is:
    http://dvanula.cz/jquery.slug2.js

    Comments for your todo:
    Ajax should stay away from this plugin, I think. For that you can use:
    http://malsup.com/jquery/form/

Leave a Reply