Removing Smart Quotes from WordPress Posts

Sample code for removing smart quotes, or curly quotes, from WordPress posts when it automatically converts normal quotes to smart quotes.

By Tim TrottWordPress • January 26, 2009
Removing Smart Quotes from WordPress Posts

This snippet will remove all smart quotes and curly quotes and replace them with standard straight quotes, and prevent WordPress from adding more smart quotes.

WordPress has a nice feature that converts the standard quotes ( " ) to pretty "curly quotes" or "smart quotes" as they are called. This is all well and good on a textual blog, but when it comes to programming code, it can be a real pain in the proverbials.

This little snippet will remove all smart curly quotes and replace them with standard straight quotes. The code needs to be placed within your theme's functions.php.

php
add_filter('the_excerpt', 'removesmartquotes');
add_filter('the_content', 'removesmartquotes');

function removesmartquotes($content)
{
  $content = str_replace("“", """, $content);  
  $content = str_replace("”", """, $content);  
  $content = str_replace("’", "'", $content);  
  $content = str_replace("‘", "'", $content);  

  return $content;
}

All this is doing is creating a new filter for the_content and the_excerpt that does a simple string replacement, from curly to straight.

There are other methods, one of which is to use:

php
remove_filter('the_content', 'wptexturize');

However, this will remove all formatting, including ampersands and so on. I had great trouble with XML after this one, which is why I wrote my own.

Related ArticlesThese articles may also be of interest to you

CommentsShare your thoughts in the comments below

My website and its content are free to use without the clutter of adverts, popups, marketing messages or anything else like that. If you enjoyed reading this article, or it helped you in some way, all I ask in return is you leave a comment below or share this page with your friends. Thank you.

This post has only 1 comment. Why not join the discussion!

New comments for this post are currently closed.