0

I am trying to convert a post title to a slug. I used sanitize_title_with_dashes, thinking that's what WordPress uses. However, if my post title has an apostrophe in it, sanitize_title_with_dashes does not strip out the apostrophe. Instead, it escapes the apostrophe with a backslash.

For example, if I use the default post editor to create a post named "Bob's Boutique", WordPress core will correctly create the slug as "bobs-boutique".

If I try to convert "Bob's Boutqiue" to a post slug using sanitize_title_with_dashes in functions.php, the result is "bob\'s-boutique".

Is there an additional function that WordPress uses when making slugs that strips out apostrophes?

  • 1
    echo sanitize_title_with_dashes("Bob's Boutqiue") outputs bobs-boutique, I don't get an escaped quote. – Milo Jan 22 '16 at 17:14
0

Use this function to remove the apostrophe:

preg_replace( "/[:’]/", "", $title );
| improve this answer | |
  • Really? Add it where exactly? Can we just drop that in functions.php and BAM! It works? – s_ha_dum Jan 24 '16 at 2:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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