WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a method or API that WordPress uses to encode the URLs similar to how it generates part of the URL when using the title in the URL? I am writing a plugin that generates URLs and would like to use the same method as everything else is.

For instance, I type "This is my blog post" in the title and "this-is-my-blog-post" gets generated.

share|improve this question
You mean you want to have generate slugs? – Raphael Nov 18 '10 at 14:38
up vote 1 down vote accepted

On a lower level, the function sanitize_title_with_dashes() converts to lowercase, replaces spaces and non-alphanumeric characters with dashes, and urlencodes whatever you pass to it.


echo sanitize_title_with_dashes( 'This is my blog post' );
// this-is-my-blog-post
share|improve this answer
This is EXACTLY what I was looking for at the time. I ended up writing a string replace function to get it working. Thanks! – Mike Wills Nov 10 '11 at 18:28

Post slugs seem to be generated by wp_unique_post_slug() function (source).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.