Posts RSS Comments RSS 60 Posts and 137 Comments till now

Permalinks Made Easy

You always want to make dynamic links using mod_rewrite to enhance your rankings.

What’s frustrating is that you often want to turn article titles into seo and url friendly dash seperated strings but that’s a much harder problem to solve than it sounds.

Thankfully Wordpress is open source and one fine day I got the bright idea to just rip out their permalink processing functions and use them on my own website.

For an example of this see NuclearSushi.Com.

Using Wordpress functions I take the database entry id, the game platform, and the game title and run it through the Wordpress cleansing functions.

This is what I then get:

http://www.nuclearsushi.com/psp/16825/crazy-taxi-fare-wars

See how everything is lower cased, all special characters are removed, and spaces are replaced with dashes?

SIDE NOTE: Always use dashes to replace spaces. I have tried underscores and Google completely hates underscores and doesn’t parse them as though they were spaces. ALWAYS USE DASHES TO REPLACE SPACES!

Ok now onto where the functions are hiding.

Head on over to http://codex.wordpress.org/Function_Reference and scroll down to the “Formatting Functions” section on the right hand side.

You’ll see a lot of functions there but the one you want is called sanitize_title_with_dashes.

You’ll see that it is located within the formatting.php, or functions.php file in a standard Wordpress installation.

Find it, copy it, put it in your source and use it.

There are some dependancies so you’ll need to turn on good old php errors and watch to see what other functions that function wants and then head back into those files and grab them.

You’ll see some crazy Unicode conversion stuff along with special cases for all kinds of characters.

Why reinvent the wheel when a great version is already available for free is what I always say!

I hope this was helpful and as always have fun & keep coding!

If you found this page useful, consider linking to it.
Simply copy and paste the code below into your web site (Ctrl+C to copy)
It will look like this: Permalinks Made Easy

Trackback this post | Feed on Comments to this post

Leave a Reply

Close
E-mail It