title: How to output radio buttons variable to frontend - wordpress
body: <p><br><br>
  I am working on my themes options panel (in administration/backend) and I am struggling with <b>radio buttons</b>.<br> <br>
  I followed this tutorial: <a href="https://github.com/cferdinandi/wp-theme-options/" rel="nofollow">https://github.com/cferdinandi/wp-theme-options/</a> for creating radio buttons. They are now in themes options but I don't know how to make output of it into themes frontend. <br><br>
  I want just to try to <code>echo</code> the value of radio buttons form but I don't know the name of the variable in which it is saved.<br><br>
  Normally in php I would do it like so: <code>if ($_POST['NAME']=="VALUE1") { echo "Some text here"; }</code><br><br>
  With text fields I use just it: <code>&lt;?php echo $options['csscolor_setting']; ?&gt;</code> (in for example header.php)<br>
  And in functions.php i have:</p>
  
  <pre><code>function csscolor_setting() {
  
      $options = get_option('theme_options');  echo "&lt;input name='theme_options[csscolor_setting]' type='text' value='{$options['csscolor_setting']}' /&gt;";
  
  }
  </code></pre>
  
  <p>But it's not possible with radio buttons. For now it would be enough if I know how to make some code like this real: </p>
  
  <pre><code>&lt;?php if ($some_variable == 'yes')
  {echo 'Something';}
  ?&gt;
  </code></pre>
  
  <p>Or just <code>&lt;?php echo $some_variable; ?&gt;</code><br>
  But this $some_variable I can't find in my code.<br><br></p>
  
  <p><b>Here is my code in functions.php regarding to radio buttons.</b></p>
  
  <pre><code>add_settings_field( 'sample_radio_buttons', __( 'Allow triangles in background?', 'YourTheme' ), 'YourTheme_settings_field_sample_radio_buttons', 'theme_options', 'general' );
  </code></pre>
  
  <p><br>
  <em>Creating options for radio buttons field</em></p>
  
  <pre><code>function YourTheme_sample_radio_button_choices() {
  
      $sample_radio_buttons = array(
  
          'yes' =&gt; array(
  
              'value' =&gt; 'yes',
  
              'label' =&gt; 'Yes'
  
          ),
  
          'no' =&gt; array(
  
              'value' =&gt; 'no',
  
              'label' =&gt; 'No'
  
          ),
  
      );
  
      return apply_filters( 'YourTheme_sample_radio_button_choices', $sample_radio_buttons );
  
  }
  </code></pre>
  
  <p><br>
  <em>Creating sample radio buttons field</em></p>
  
  <pre><code>function YourTheme_settings_field_sample_radio_buttons() {
  
      $options = YourTheme_get_theme_options();
  
      foreach ( YourTheme_sample_radio_button_choices() as $button ) {
  
      ?&gt;
  
      &lt;div class="layout"&gt;
  
          &lt;label class="description"&gt;
  
              &lt;input type="radio" name="YourTheme_theme_options[sample_radio_buttons]" value="&lt;?php echo esc_attr( $button['value'] ); ?&gt;" &lt;?php checked( $options['sample_radio_buttons'], $button['value'] ); ?&gt; /&gt;
  
              &lt;?php echo $button['label']; ?&gt;
  
          &lt;/label&gt;
  
      &lt;/div&gt;
  
      &lt;?php
  
      }
  
  }
  </code></pre>
  
  <p><br>
  <em>Getting the current options from the database and setting deafaults.</em></p>
  
  <pre><code>function YourTheme_get_theme_options() {
  
          $saved = (array) get_option( 'YourTheme_theme_options' );
  
          $defaults = array(
  
              'sample_checkbox'       =&gt; 'off',
  
              'sample_text_input'     =&gt; '',
  
              'sample_select_options' =&gt; '',
  
              'sample_radio_buttons'  =&gt; 'yes',
  
              'sample_textarea'       =&gt; '',
  
          );
  
          $defaults = apply_filters( 'YourTheme_default_theme_options', $defaults );
  
          $options = wp_parse_args( $saved, $defaults );
  
          $options = array_intersect_key( $options, $defaults );
  
          return $options;
  
      }
  </code></pre>
  
  <p><br>
  Then there is a little bit more code about sanitization and validation but I think it should not have any inffluence on variable in form. <br> <br></p>
  
  <p>Thank you in advance.</p>