Checkbox in theme options

1

I'm creating an options page for my Wordpress theme, but I'm having some difficulty related to checkbox .

The idea is this: If the checkbox infra_bloco1_visivel is checked it will enable a div of content on the page. If it is unchecked, nothing appears.

In options page checkbox looks like this:

$options[] = array(
    'name' => __('Bloco 1', 'options_check'),
    'desc' => __('Visível', 'options_check'),
    'id' => 'infra_bloco1_visivel',
    'std' => '1',
    'type' => 'checkbox');

The logic will be something like "If 'infra_label_visible' is checked , show the DIV such (or anything else) if it is not checked showing nothing.

    
asked by anonymous 19.11.2014 / 23:05

1 answer

1

In fact your solution is in a client-side language, in the case of javascript, it follows a solution that would solve

link

<input type="checkbox" class="checkbox" checked="checked" />Marque para mostrar ou ocultar
<br />
<div class="conteudo">conteudo a ser mostrado</div>

<script>
    function mostrarOcultar(){
        if($(".checkbox").prop("checked"))
            $(".conteudo").show();
        else 
            $(".conteudo").hide();
    }

    $(function(){
        mostrarOcultar();
        $(".checkbox").click(mostrarOcultar);
    })

</script>
    
30.11.2014 / 18:15