Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is the code I have to display the checkbox in the theme options page:

$options[] = array( "name" => "Enable/Disable Slider",
                "desc" => "If you don´t want to see the slider on your homepage you can disable it here.",
                "id" => $shortname."_onoffslider",
                "std" => "",
                "type" => "checkbox",
                "class" => "");

The checkbox now is there. And also I have this bit of code to echo the value true or false in my template. like this:

            <p>
            <?php if( get_option('_onoffslider') != '') { ?>
            <?php echo get_option('_onoffslider'); ?>

            <?php } else { ?>

            It is ON!

            <?php } ?>
        </p>    

In the template page the text "It is ON!" always shows, no matter the checkbox is on or off. I know the code is wrong but i can´t fix it.

Any help? thanks =)

share|improve this question
nevermind. I got it working! – Ricardo Ribeiro Jan 8 '12 at 11:48

closed as too localized by kaiser, toscho Apr 7 '12 at 20:49

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

If I'm correct when you use the checkbox on options it saves a value when it is checked but when it's not it doesn't save one so basically it has a null value and it is going to be always != ''. Try dumping the retrieved value ( var_dump(get_option()) ) then you'll be sure what does it return

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.