Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

2 Answers 2

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.

<?php

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

 
discard

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.