May 12, 2016

WordPress helper function checked

WordPress helper function checked

Older Method:

<input type=”checkbox” id=”tutorsloop_share” name=”wpe_sharing[social_options][]” value=”tl” <?php echo¬† in_array( ‘tl’, $opts[‘social_options’] )?’checked=”checked”‘:”; ?> />

Preferred Method:

<?php checked( in_array( ‘tl’, $opts[‘social_options’] ), true ); ?>

<input type=”checkbox” id=”tutorsloop_share” name=”wpe_sharing[social_options][]” value=”tl” <?php checked( in_array( ‘tl’, $opts[‘social_options’] ), true ); ?> />

Click here for details on WordPress.org

Click here for screenshots

Last updated: May 12, 2016