Skip to main content

Make the checkbox meta field checked by default

I have created a page for plugin. For that page i have added a checkbox meta field. The field is working fine. By default, the checkbox field is unchecked. I mean at first to active the plugin, the checkbox field is unchecked. But I need to make it check by default. I have tried a condition but not working at all. My code is :

function ins_street_address_shortcode_callback(){
    $val = get_option('ins_street_address_shortcode');

    $checkval = "";

    if ($val == 'on'){
        $checkval = "checked";
    }

    printf("<input type='checkbox' name='ins_street_address_shortcode' %s />", $checkval);
}