php - Radio Buttons not showing up as checked -
i'm trying write theme options page wordpress. in it, user select alignment of div through radio buttons.
currently looks when option selected: https://gyazo.com/e27c2fc2c2e1f751ab27d98453581c52
i wondering how i'd fix (for radio buttons show checked , not checked='checked'center). works , correctly outputs front-end doesn't show checked without checked='checked'. if use jquery remove checked='checked' removes radio buttons together.
register_setting('slider_setting','slider_section1_direction'); add_settings_section( 'slider_section', '', 'slider_settings_callback', 'register_slider_settings' ); add_settings_field( 'slider_section1_direction', '', 'slider_section1_direction_callback', 'register_slider_settings', 'slider_section' ); function slider_section1_radio_buttons_callback() { $s1_radio_buttons_settings = array( 'left' => array( 'value' => 'left', 'label' => 'left' ), 'center' => array( 'value' => 'center', 'label' => 'center' ), 'right' => array( 'value' => 'right', 'label' => 'right' ), ); return apply_filters( 'slider_section1_radio_buttons_callback', $s1_radio_buttons_settings ); } function slider_section1_direction_callback() { $settings = get_option('slider_section1_direction'); echo '<div class="setting">'; echo '<div class="setting-header half-width-header">'; esc_attr_e('slider text alignment'); echo '</div>'; echo '<div class="setting-body" style="margin-top: 5px">'; // radio buttons foreach ( slider_section1_radio_buttons_callback() $s1_button ) { echo '<label class="description" style="margin-right: 40px">'; echo "<input type='radio'" . checked( $settings['s1_radio_buttons_settings'], $s1_button['value'] ) . " name='slider_section1_direction[s1_radio_buttons_settings]' value='" . esc_attr( $s1_button['value'] ) . "'/>"; echo $s1_button['label']; echo '</label>'; } echo '</div>'; echo '<div class="clear"></div>'; echo '</div>'; } function slider_settings_callback() { }
thanks!
i checked documentation checked
function, , looks echos checked="checked"
attribute. however, because want concatenate string, want return attribute instead. luckily third parameter in function can set false
cause function return attribute instead. change usage of function this:
checked( $settings['s1_radio_buttons_settings'], $s1_button['value'], false)
notice false
@ end of function.
Comments
Post a Comment