Create WordPress like slugs in PHP

akshitsethi —  October 20, 2013 — Leave a comment

This is an quick tutorial. I will show you how we can create perfect WordPress like slugs in php using just few lines of code. Have a look at the php function below.

Let’s understand how we are creating the slug from a title passed to this function. Firstly, all the white spaces are converted to hyphens(-) and then all other characters are removed except letters, numbers, and hyphens. That is all we have to do to create a perfect slug for our pages.

akshitsethi

Posts

I am a designer+developer by profession and entrepreneur by passion. I work on LAMP platform and can design+develop small static websites to high performing enterprise web applications. In love with the web and addicted to Spanish.