• Wordpress, Stop Changing My Quotes!

  • By: Jarod Taylor | Category: Wordpress
  • Alright, so you're copying and pasting something from your blog post into another website and instead of getting Mom's Yummy Cookies you get Mom‘s Yummy Cookies. Of course, the site doesn't allow you to edit anything, so you're screwed.

    Okay fine, you caught me, this happened to me. While I wasn't boasting about my mother's delicious cookies, I still endured something very similar while promoting a post. What I'm referring to is Wordpress' default rendering of both single quote and double quote characters.

    You'll notice when you create a post in Wordpress; your boring, yet standard, single quote ' gets turned into ‘ and your double quotes " get turned into “. This is what they call "Smart Quotes". What Wordpress is actually doing is replacing the simple, universal, single quote and double quote characters and rendering them as either left single/double quote or right single double quote characters. Let's take a look at it closer.

    You type: Mom's Yummy Cookies
    Wordpress renders: Mom’s Yummy Cookies

    OR

    You type: Mom told me to tell you "Hello".
    Wordpress renders: Mom told me to tell you “Hello”.

    Let's face it, the Wordpress way is much sexier! Unfortunately, it will cause you problems in situations where you're copying and pasting content from one blog to another, especially in situations where you're pasting code from one blog to another. More over, some applications will not know how to handle these beautiful smart quotes, hence your sexiness is rendered Mom‘s Yummy Cookies. Even worse, if this were a blog post title, word on the street is, Google doesn't like Smart Quotes and may not even index your post correctly. Oh noes! We don't want to upset the Google Gods.

    Okay, I get it! Tell me how to fix it!

    Alright, so you want to fix this huh? It's really simple. In your Wordpress theme's directory, open up your functions.php file. There are several Wordpress plugins available for doing this, but I personally prefer to go about it without plugins if I can. If you currently do not have a functions.php file in your theme, go ahead and create one.

    There a few different choices when deciding to disable the "smart quotes" from your blog, but we'll focus on just the 4 main options when working with the Wordpress texturize filter. The 4 main choices are your post's title, post's content, post's excerpt, and your comment text.

    You simply need to put the one's you're looking to disable at the bottom of your functions.php file.

    Remove from Post Content
    <?php
    remove_filter('the_content', 'wptexturize');
    ?>
    
    Remove from Post Title
    <?php
    remove_filter('the_title', 'wptexturize');
    ?>
    
    Remove from Post Excerpt
    <?php
    remove_filter('the_excerpt', 'wptexturize');
    ?>
    
    Remove from Post Comments
    <?php
    remove_filter('comment_text', 'wptexturize');
    ?>
    

    Disable it on certain parts of a post?

    Well, there are a couple of options here. You could use a plugin, which would be the easiest, or, you could use the proper HTML character entities in your post, and keep wptexturizer enabled.

    Symbol HTML Name HTML Number Description
    " &quot; &#34; Double Quote
    '   &#39; Single Quote
    &lsquo; &#8216; Left Single Quote
    &rsquo; &#8217; Right Single Quote
    &ldquo; &#8220; Left Double Quote
    &rdquo; &#8221; Right Double Quote

    Well, that's it for this quick tip. Let me know if you have any questions! Thanks.