0

Wordpress converts my theme options text with smart quotes.

I know that to remove problem from posts etc:

remove_filter('the_content', 'wptexturize');

remove_filter('the_excerpt', 'wptexturize');

remove_filter('comment_text', 'wptexturize');

But how to remove this effects when saving into Wordpress options api?

2 Answers 2

0

WordPress does not automatically texturize options. If you are using add_option(), update_option(), and/or get_option() then it should "just work".

Example:

//Add an option to the database
update_option('my_test_option','This is an option. Isn\'t it "special"?');

//Returns string: This is an option. Isn't it "special"?
echo get_option('my_test_option');
0

Use a function to replace the smart quotes (following is based on code from this plugin), in functions.php:

function wpse89095_untexturize( $text ) {
    $char_codes   = array( '‘', '’', '“', '”', '′', '″' );
    $replacements = array( "'", "'", '"', '"', "'", '"' );
    return str_replace( $char_codes, $replacements, $text );
}

Then filter your option before it's saved to the database, in functions.php:

function wpse89095_untexturize_option( $newvalue, $oldvalue ){
    $newvalue = wpse89095_untexturize( $newvalue );
    return $newvalue;
}
add_filter( 'pre_update_option_{OPTION}', 'wpse89095_untexturize_option', 10, 2 );

NB: replace {OPTION} with the name of the option you'd like to filter.

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.