As a developer, we're often left with the responsibility of making game time decisions in regards to SEO. I take it upon myself to maximize keyword relevancies for each and every page; starting with the URL, title, and H2 tag (leaving the H1 solely to the site name). Many people take for granted things like Permalink generation in Wordpress. If you were to delve behind the scenes, into the depths of the code, you would realize that there is much more to that pretty hyphenated link than meets the eye.

I have created a multi-purpose generator which uniquely generates clean URLs given the target table name, column name, input string, and maximum column length. The generator will not only strip or replace unwanted characters, but also only output full words. In the event of a clean URL collision (duplicate), the method will recurse and incrementally test postfix integers until a unique URL is generated. The only requirements are that you have instantiated $this->_db to your database adapter prior to calling this method. The easiest usage for this method is to drop it in a base class that would be inherited by all of your models.

Source code can be found here on github.

Forks and pull requests are welcome.


Credit goes to Matteo Spinelli for the initial code that spawned this extension