I'm having some troubles with a extra feature i'm writing for my theme.

The admin should be able to make some special posts, those posts are stored as an option. The options are atored as an array and WP makes it's own json for arrays.

So, the user has a wp_editor(), and the array stored looks something like this:

    'title' => 'My title',
    'content' => 'Look at my cat! <img src="mycat.jpg" />', //Generated by wp-editor
    'signature' => 'My name'

The thing is, when an image is added to this content, the image string is quite badly escaped. When i'm trying to get this content i get it as

<img src="\"mycat.jpg\"" />

instead of

<img src="mycat.jpg" />

How can i store content like this in the wp-options table so i can get it right when i try to get the content?

1 Answer 1


If you just want to get rid of the \ characters in the string that's returned, you can use PHP's stripslashes():

$content = stripslashes( $content );

I'd recommend doing this on output rather than on input; WordPress adds the slashes as it sanitizes your data on insert, per update_option()'s Codex page,

The $option (option name) value is escaped with $wpdb->escape before the INSERT statement.

See Data Validation for way more information.

  • Too simple! Simple is always best tho! ;) Thank you
    – gubbfett
    Commented Dec 11, 2013 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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