WordPress checked="checked" syntax

Only a few week age, I established a simple plugin for myself to showing the social share button in menu. Referred to Building Your Own Social Sharing Plugin for WordPress.

Then, the plugin was successful created. But I have a question of the syntax why If I added the below syntax in the program the checked=”checked” will showing twice.

echo "<input type='checkbox' name='social-share' value='1' " . checked(1, get_option('social-share'), true) ." /> "; 

After that, I found another code to prevent this happen.

  <input type="checkbox" name="social-share" value="1" <?php checked(1, get_option('social-share-wechat'), true); ?> /> Check for Yes

and Function Reference/checked displaying checked=’checked’

checked( '1', get_option( 'wwo_enable_'.$lrole ), false )

I wondered if anyone can tell me why using HTML format to show the syntax will not show twice?

Read more here: WordPress checked="checked" syntax

Leave a Reply

Your email address will not be published. Required fields are marked *