1

currently I try to write a callback for a Wordpress option of my theme with the settings API. This is my function:

    function background_callback($args){
    printf(
        'Picture 
         <input 
               type="radio" 
               name="%1$s[%2$s]" 
               onclick= "showChoosenField("%3$s")" 
               value="<?php checked("%3$s", get_option("%1$s[%2$s]"), true); ?>"
          />
         <input 
               type="radio" 
               name="%1$s[%2$s]" 
               onclick= "showChoosenField("%4$s")" 
               value="<?php checked("%4$s", get_option("%1$s[%2$s]"), true); ?>"
          />   
         Color
         <p></p>
         <label for="%2$s">%5$s / %3$s/ %4$s</label>',
        $args['option_name'],
        $args['namePic_Color'],
        $args['valuePic'],
        $args['valueColor'],
        $args['description']
        );
    }

But when I look at the browser I get this output:

<td>"Picture"
    <input 
          type="radio" 
          name="header_options_group[img_color_name]" 
          onclick="showChoosenField(" ")" 
          value="<?php checked(" ", get_option("header_options_group[img_color_name]"), true); ?>
          ""
    />"
    <input 
          type="radio" 
          name="header_options_group[img_color_name]" 
          onclick="showChoosenField(" ")" 
          value="<?php checked(" ", get_option("header_options_group[img_color_name]"), true); ?>
          ""
    /> Color" 
    <p></p>
    <label for="img_color_name">
          Please check if you want a Picture or a color. / / 
    </label>
</td>

From where are the quotes at the end of the at the line 7,8 and 14,15? I tried so many things to get rid of this things. But no matter what I change they stay there, or some other quotes appear at another places. I concatinated every thing, deleted different parts, but no way.

I assume its because the php in the printf. Did someone know why this happens? Or if its because the php how I can change it that it works? I have no ideas anymore. Thank you.

  • Read this stackoverflow.com/questions/6168298/… – Ranuka Nov 21 '16 at 11:26
  • @Ranuka Never mind, it works with that '<input type="radio" name="%1$s[%2$s]" onclick= "showChoosenField(\'%3$s\')" value="<?php checked(\'%3$s\', get_option(\'%1$s[%2$s]\'), true); ?>"/>'. Thank you very much ! – theoretisch Nov 21 '16 at 11:42
  • i think the problem is coming from the $args variables you passing into printf() function , try replace them to normal string. eg. 'option_name','color','pic','valuecolor', 'description' ); lets try it. – Govind Kumar Nov 21 '16 at 11:43
0

You have to escape the quotation marks like this.

<input type="radio" name="%1$s[%2$s]" onclick= "showChoosenField(\'%3$s\')" value="<?php checked(\'%3$s\', get_option(\'%1$s[%2$s]\'), true); ?>"/>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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