From York to New York – out with the old, in with the new

Clean Trunks – Wordpress Plugin

Automated SEO Friendly URL plugin for Wordpress

Download SEO Wordpress PluginDownload

Background

A common situation that frustrates me is the length that WordPress slugs amount to with auto-generation. Sure, its easy to update the slug permalink from the admin interface but in multi-access scenarios not everyone thinks about it or realises the benefit of optimizing the latter.

For good SEO, we need to keep the URL relatively short with targeted keywords present, this plugin will filter the proposed page name against a stopword list and hopefully retain good keywords all the whilst truncating the url to a reasonable size.

Plugin Description

Clean Trunks provides SEO Friendly URLs for post and page slugs automatically. This plugin does smart trunking on word boundaries to a configurable maximum number of characters. `Smart trunking` is achieved by use of an updateable keyword stoplist to help create those perfect SEO urls automatically.

Features

  • Plugin configuration page where the maximum url length can be changed and the stopword list edited.
  • Default stopword list supplied and loaded.

Installation

  1. Extract the zip archive to your plugin folder, make sure it is in its own subfolder or deactivation and activation routines may fail. e.g: wp-content/plugins/clean-trunks.
    The zip contains two files: `clean-trunks.php` (the plugin) and `stopwords.txt` (default stopword list). The latter is used to load a default stop word list for the plugin to filter against once activated.
    Note: If you deactivate the plugin at any point, make sure you have a `stopwords.txt` file in the plugin subfolder.
  2. Activate the plugin in the Wordpress administration area.

Instructions

Activate the `Clean Trunks` plugin after installation as above. Under Options you’ll find an administration interface where you can:

  • Update the maximum url size which the truncation will work towards. Default: 35 characters.
  • Edit the stop words filter list.

You can always revert to the original stop word list by de-activating and re-activating the plugin at any time.

Warning! If you save previously published posts with the plugin activated the url may change so make sure you account for this with rewrites. The option to bypass the plugin is in the Todo list which i hope to iron out soon.
Clean Trunks now ensures that previously existing permalinks do not change url when being edited after plugin installation. :-)

Download

Download SEO Wordpress Plugin Download the Clean Trunks v1.0 plugin

Todo/Wishlist

- Internationalisation of the stop words list and potential hic-ups in filtering.
- Better stopword list user-experience for updates/deletions.
- Further bug testing.
- Override option within post/page editing interface to manually bypass this plugin.

Version History

v1.0

  • Bug fix: Stopwords are converted to lowercase for comparison.
  • Bug Fix: Explicitly set to ignore blank lines in stopwords.txt
    Thanks to Justin @ Walker Art for these suggestions.

v0.9

  • Clean SEO slugs were not being applied when publishing but only after subsequent edit. Current behavior is to only clean trunk permalink when actually publishing.
  • Pre-existing posts prior to installation retain their permalink when re-saving.

v0.8

  • Initial Release of Clean Trunks, the SEO Friendly URL plugin for Wordpress
21 comments


21 Comments so far

  1. DragonFlyEye January 19th, 2007 10:56 pm

    Your assistance, please!

    I am noticing that the Clean Trunks plugin only seems to be working when I edit an already-existing post. I mean to say that I have the plugin installed, I write a post and publish, but the slug is not optimized. However, I edit this same post and the slug gets changed to the optimized version.

    I have also tried just saving a post without publishing it, then going back and editing it and publishing it to see if that would make any difference or not. Not.

    I’ve tried combing through the code, but since I don’t really understand the mechanics of how WordPress posts articles, I don’t really see anything wrong.

    Thanks for any help you can give me!

  2. whipster January 20th, 2007 2:52 pm

    Hi DragonFlyEye,

    Thanks for reporting your issue. I can verify that this is indeed happening. The plugin is designed to use the Wordpress hooks architecture to avoid the need to make custom edits to the core Wordpress source code which is an excellent feature. Unfortunately, when creating a new post, Wordpress doesn’t appear to run the slug optimisation code (it doesn’t use the hook that the plugin responds on). Initial investigation reveals that to have the slugs tidied up on publishing new posts would require editing Wordpress source files which i’d rather not do, I am looking into any other Wordpress hooks that may be able to do the intended job. I’ll post an updated version of the plugin when that occurs.

    Regards,
    Adam

  3. whipster January 21st, 2007 2:30 am

    An updated version of Clean Trunks is now available for download, please see the version history for more information.

  4. whipster January 22nd, 2007 9:21 pm

    I eventually had to rework much of the source code to use database updates rather than filtering the urls on the fly thanks to Wordpress’s plugin architecture. Its a pity that the hook reference documentation doesn’t get more active contribution from the community as it can be quite complex. I’ll make every effort to help out with such documentation, it is rather invaluable. And let’s face it, not doing so would disqualify me of being one of the Time’s Person of the Year. :-)

  5. cube January 23rd, 2007 11:10 am

    Hi there,

    After my upgrade to 2.10 last night I’m finding that I get a repeatable, or at least semi-repeatable, and unexpected PHP error returned when I’ve got Clean Trunks active. After looking at the code, though, this may have been present before but I didn’t get the error.

    Anytime I click “Post”, which runs /wp-admin/post.php I get this return:
    Fatal error: Call to undefined function: len() in /home/xxx/xxx/sadmac.org/blog/wp-content/plugins/clean-trunks/clean-trunks.php on line 80

    since len() is not defined in php, this be sizeof() (which aliases count()). After changing the function call to sizeof(), the error is gone and the SEO trunk is in place.

    I’ll send my invoice ;) Just Kidding! thanks for your work! My first contribution to open source. Tip your 40s.

  6. whipster January 23rd, 2007 11:30 am

    That’ll teach me to work late :-)
    I’ve updated the downloadeable zip file but rather than use sizeof() i corrected the compile error with strlen() as we are testing that the optimised url isn’t longer than the max number of characters set in the admin GUI. Thanks for letting me know cube, much appreciated.

  7. cube January 23rd, 2007 11:51 am

    Ah, doh, you’re right. strlen() is correct. My eyes didn’t go past the function call to see that you were testing the length of the first array element. Thanks for the fast turnaround! I’m still a little confused why this was not coughing on me under WP 2.7, but some things are probably better left unknown.

  8. Matt Irwin February 12th, 2007 1:58 am

    I seem to getting a bug changing the length from the default. If I leave it at 35, it clips and filters out stopwords. If I increase (tried 45 and 50), it clips it fine, but doesn’t filter stopwords. It could definitely be some other glitch in my installation. Thought you might want to know if it is in fact a bug.

  9. Matt February 17th, 2007 12:30 am

    One more thing. I just added some code to check if the strlen of $newname is 0. In that case, the original name is used. I was trying to save an “About Us” page and since both words were on the stopwords list, the slug was empty.

    Replaced:
    $wpdb->query( “UPDATE $wpdb->posts SET post_name = ‘$new_name’ WHERE ID = ‘$post_ID’” );

    With:
    if (strlen($new_name)==0)
    $wpdb->query( “UPDATE $wpdb->posts SET post_name = ‘$post_name’ WHERE ID = ‘$post_ID’” );
    else
    $wpdb->query( “UPDATE $wpdb->posts SET post_name = ‘$new_name’ WHERE ID = ‘$post_ID’” );

    in the two places it appears. Thanks again for the great plugin!

  10. whipster February 25th, 2007 7:33 pm

    Thank you Matt, you’re comments are much appreciated! I’ve integrated the code change you suggested into the current version of Clean Trunks. Happy Trunking! :-)

  11. justin April 23rd, 2007 2:56 pm

    Great plugin, very useful. I noticed a couple bugs that I’ve fixed..

    First, the function that imports the stoplist doesn’t always ignore newlines. Calling file() in cltk_install (around line 55) should be:

    $arr_stopwords = file( dirname(__FILE__) . $this->stopfile, FILE_IGNORE_NEW_LINES );

    You might also want to use the strtolower() function when testing the stop words in cltk_is_stopword(), add a line at the beginning:
    $word = strtolower($word);

    And you might want to change line 128 of cltk_install to change things to lower case as well:

    $arr_stopwords[$sKey] = strtolower(trim( $sValue ));

    I also noticed that when I unzipped the file, the quotes on the queries were a bit messed up, showing some weird characters. Dunno if it was just some text encoding thing, but I do know the post above has curly quotes, which might be part of the problem.

  12. whipster April 23rd, 2007 7:47 pm

    Great feedback Justin, thank you for taking the time to help the plugin evolve and become more robust. I will look to incorporate your suggestions and post an updated plugin for the community.

    Cheers!
    Adam

  13. whipster May 12th, 2007 10:11 pm

    Clean Trunks has now been updated with a few bug fixes detailed above and in the readme file. I am also releasing it as v1.0 (Yes!!!) since i feel it is now in a good state for major release versioning. Enjoy!!!

  14. ovizii May 15th, 2007 1:08 am

    thx for the nice plugin. I especially like the inclusion of stopwords. do you know where I could get stopwords lists for other languages?

    I was formerly using this plugin: http://pietersz.co.uk/2006/07/wordpress-slug-trimmer it has some other nice features, like skipping of words up to a certain length, etc. Have a look maybe you can get some new ideas for your own plugin.

    Btw. if I enter the slug manually into the slug-field, does your plugin still “trimm” it? I mean sometimes, however very rarely, I enter my slug manually and don’t want it modified…

  15. DragonFlyEye July 12th, 2007 9:53 am

    Thanks for the great plugin! I’ve been using to great effect for a number of months and it’s going great.

    Question: I’m switching over to WordPress MU and wondering if anyone has tried this on an MU installation and if so, what the success or failure has been?

    Thanks again!

  16. Matt January 3rd, 2008 9:35 pm

    Thanks for the this useful plugin! Hopefully this will help me avoid any more Google indexing issues…

  17. videoclipuri January 30th, 2008 8:57 am

    Cheers..Very good plugin

  18. Michael March 14th, 2008 8:59 am

    Looking forward to giving this a try – Thanks for the work, and the transparent documentation.

  19. Online Marketing Guy April 25th, 2008 5:05 pm

    Hey, should I assume that this will work for either a Windows (IIS) or Linux (Apache) installation?

  20. Sheridan May 5th, 2008 3:46 pm

    I wrote 400 posts in wordpress before realising the benefit of seo friendly urls. I now want to use them from this point on. But as I still get many google hits from the old 400 posts, I don’t want to lose them. Will this plugin get round that problem?
    Thanks

  21. whipster August 26th, 2008 2:15 pm

    I tested this on IIS and Apache and appears to work fine. Would be interested to hear if anyone has observed otherwise.

Leave a reply