Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Custom Metaboxes Checkboxes

I cant seem to figure out how to echo checkboxes?

I have a setting on pages to hide the logo. I have the code below in a css/php file

<?php if ( $meta_boxes ['wpex_hide_logo'] == '1') { echo "#logo {display:none !important;}";} ?>

Currently using CMB2 https://github.com/WebDevStudios/CMB2

For refrence

$meta_boxes[] = array(
        'id'            => 'wpex-hide-meta',
        'title'         => __( 'Feature Settings', 'wpex' ),
        'pages'         => array( 'page' ),
        'context'       => 'normal',
        'priority'      => 'high',
        'show_names'    => true,
        'fields'        => array(

            array(
                'name' => __( 'Test Checkbox', 'cmb2' ),
                'desc' => __( 'field description (optional)', 'cmb2' ),
                'id'   => $prefix . 'hide_logo',
                'type' => 'checkbox',
            ),
),
);

Getting closer

This hides the logo even if the check box is not checked

<?php if($wpex_hide_logo = get_post_meta( get_the_ID(), 'wpex_text', true )) {echo "#logo {display:none !important;}";} ?>

Figured it out

<?php if(get_post_meta( get_the_ID(), 'wpex_hide_logo', true )) {echo "#logo {display:none !important;}";} ?>