Stop WordPress from curling up your quotes

If you are using WordPress for blogging and you write regular text without the need for displaying the source code, you might have not even noticed what WordPress is doing to your quotes. By default, WordPress will automatically format your text and thus change the way regular quotes are being displayed in your posts.

While this won’t have any influence on your text, and it actually might look better for a reader when you have curly quotes, it might become a nasty problem for someone who deals with the code.

If you write a code directly in your editor, you will need to use regular quotes, without curls attached to them. Looks of those quotation marks aren’t really the problem, but their HTML code which actually defines them is. So, if you let WordPress change your regular quotes and change them to curly ones, the output will have a different code behind it.

After you publish your post with the code in it, copy the code and paste it back into your functions.php file, for example. If you do that, you will end up receiving an error because your WordPress won’t recognize the code correctly.

Now that you know why this little change actually can be a big one, let’s stop WordPress from automatically format your posts by creating a simple shortcode.

  1. Navigate to your functions.php file and open it
  2. Copy and paste this code (don’t worry, we have taken care of curly quotes for you):
  3. function my_formatter($content) {
    $new_content = '';
    $pattern_full = '{(\[raw\].*?\[/raw\])}is';
    $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
    $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
    foreach ($pieces as $piece) {
    if (preg_match($pattern_contents, $piece, $matches)) {
    $new_content .= $matches[1];
    } else {
    $new_content .= wptexturize(wpautop($piece));
    return $new_content;
    remove_filter('the_content', 'wpautop');
    remove_filter('the_content', 'wptexturize');
    add_filter('the_content', 'my_formatter', 99);
  4. Save changes
  5. Edit any post and try out the shortcode like this:

[raw] This sentence contains raw “quotes”. [/raw]

This sentence is still formatted by WordPress and contains curly quotes.

As you can see from the example, if you want to make sure your code is formatted correctly, all you have to do is put the code behind [raw] shortcode while all the other text will still look a little more beautiful with the curly quotes.

If you don’t like creating your own shortcodes, you can use Smart Quote Fixer plugin.

Start Blog Book


This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *