Support » Plugins » how to store html in wp_options

  • Resolved teamplaylotto


    I have a plugin that a user can specify some html code in the options page to be added to the output of the plugin. if the content is using double quotes then all is fine but if the html contains single and double quotes then things can go a bit screwy.

    what is the best way to store html in wp_options and have it come back as it was entered?

    ie. user submits the options page and it has a textarea with
    <br /><a class='myclass' href="">Some "quoted" text and apostrophe's</a>

    how to store that without errors and be able to echo it out to the page to be displayed as html to be rendered by the browser?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You could try using the function addslashes before you save the option.

    $html_code = addslashes($_POST[‘html_code’]);
    update_option(‘myoptionname’, $html_code);

    Then when displaying the code you use the stripslashes function.

    $myoption = stripslashes(get_option(‘myoptionname’));
    echo $myoption

    thanks for replying.
    I did some playing with addslashes and it appears it might act differently if magic quotes are on so I now use this

    // add slashes to html if magic quotes is not on
    function atf_slashit($stringvar){
        if (!get_magic_quotes_gpc()){
            $stringvar = addslashes($stringvar);
        return $stringvar;
    // remove slashes if magic quotes is on
    function atf_deslashit($stringvar){
        if (1 == get_magic_quotes_gpc()){
            $stringvar = stripslashes($stringvar);
        return $stringvar;

    and add the html returned by the settings page by


    that seems to work and should be compatible if someone doesn’t have magic quotes on

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how to store html in wp_options’ is closed to new replies.