Graeme's

You can get new post notifications through RSS, email, Twitter or Facebook

WordPress plugin: Slug Trimmer

Posted by Graeme in Wordpress at 9:10 am on Saturday, 15 July 2006

I have got sick of URLs that end in really long post slugs that look-something-like-this-and-are-far-too-long so I wrote a little plugin that shortens post slugs more intelligently than simply truncating them.

It works in two phases. It first removes short words (because words like “a” and “the” are rarely significant), shortest first.

If the slug is still too long, it is then truncated. However slugs will never be truncated mid-word.

The size of words removed the the first phase and both the minimum and maximum lengths of the slug resulting can be configured. Truncation can be turned off. The point at which the slug is truncated is set separately from the maximum for the purposes of phase one (word removal).

The slug is generated on saving a post (so you get a chance to look at it before publishing), or on publish. It will not overwrite an existing slug, even one generated by itself. You can force the generation of a new slug by deleting the existing one.

Installation and configuration is simple. Download Slug Trimmer here. If you want to change the configuration, the options will appear as a sub-panel of “Options” in your WP Admin.

If you find this plug useful and feel inclined to do me a favour: I would really appreciate links to any of my money-making sites. I most need links to internal pages of Moneyterms, or to either the front page or the books section of PTZ.com.

Comments (11)

Comments(11)

Comment by skcsknathan001 at 9:36 pm on 15 December 2006 at

Your plugin skips the trimming if the blogger enters the text right in the Post Slug box when posting.

I tried to hack and then your post slug gets replaced by the title when updating a post.

Comment by Graeme at 8:36 am on 16 December 2006 at

It is deliberate: I assumed that if someone entered a post slug manually, then that is what they wanted.

What changes did you make to the code.

Comment by skcsknathan001 at 5:06 pm on 16 December 2006 at

Here is the link to the modified file.
http://adadaa.com/misc/slug-trimmer.txt
[of course change the extention to .php]
It seems like the function is not at all called when updating a Post. And WordPress somehow replaces the existing Post Slug with Post Title.

Waiting for your update

Comment by skcsknathan001 at 8:14 pm on 18 December 2006 at

http://mu.wordpress.org/forums/topic.php?id=2856&replies=5

Comment by Yamato-Soft Blog » Blog Archive » Putting Keywords in Your URLs at 9:02 am on 17 January 2007 at

[…] Also, I’d avoid too many hyphens in the URL, as that can look spammy. Try to keep it to three or fewer. Unless your site is powered by WordPress, in which case Google probably makes an exception for that, given how popular it is and how many legitimate bloggers have loads of hyphens in their permalink URLs. By the way, you can trim those down using the Slug Trimmer plugin for WordPress. […]

Comment by Reasons Not to Use Keywords in Your URL’s at 8:21 am on 26 April 2007 at

[…] words at some point down the road you’ll have problems (if you are on wordpress try the slug trimmer plugin it’s pretty […]

Comment by Graeme’s > Wordpress plugin: Slug Trimmer at 9:42 pm on 10 June 2007 at

[…] http://pietersz.co.uk/2006/07/wordpress-slug-trimmer “shortens post slugs more intelligently than simply truncating them.”Tags: wordpress, plugin, blog(del.icio.us history) […]

Comment by Things I do to optimize and secure every WordPress site and blog » wordpressgarage.com at 8:39 am on 6 July 2007 at

[…] Slug Trimmer – if you use pretty permalinks, they are formed from the titles of your posts. Sometimes the titles are long, and then you end up with a really long URL. This plugin trims the URLs automatically. […]

Comment by Shorten Your Blog Post URLs So You Don’t Look Spammy to Google at 9:51 am on 23 January 2008 at

[…] i.e. to five or six words. There are two plugins to choose from that will accomplish this: the WordPress Slug Trimmer plugin or the Automated SEO Friendly URL […]

Comment by Shorten Your Blog Post URLs So You Don’t Look Spammy to Google at Business Consulting at 8:09 pm on 25 February 2008 at

[…] i.e. to five or six words. There are two plugins to choose from that will accomplish this: the WordPress Slug Trimmer plugin or the Automated SEO Friendly URL […]

Comment by Kolam Designs at 11:52 am on 5 March 2010 at

Installation and configuration is simple, it really works fine.

Sorry, comments are closed