Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Last active September 23, 2015 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronalfy/a2fc8649139c7bf4188d to your computer and use it in GitHub Desktop.
Save ronalfy/a2fc8649139c7bf4188d to your computer and use it in GitHub Desktop.
CMB2 + Customizer
add_action( 'cmb2_init', function() {
$cmb = new_cmb2_box( array(
'id' => 'address',
'title' => __( 'My Address', 'cmb2' ),
'object_types' => 'customizer', // Post type
'context' => 'normal',
'priority' => 800,
'show_names' => true, // Show field names on the left
) );
// Regular text field
$cmb->add_field( array(
'name' => __( 'Street Address', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => 'cmb_street_address',
'type' => 'text',
) );
// Regular text field
$cmb->add_field( array(
'name' => __( 'File', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => 'cmb_file_1',
'type' => 'file',
) );
// Regular text field
$cmb->add_field( array(
'name' => __( 'Text URL', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => 'cmb_text_url',
'type' => 'text_url',
) );
// Regular text field
$cmb->add_field( array(
'name' => __( 'Text File', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => 'cmb_file_2',
'type' => 'file',
) );
// Regular text field
$cmb->add_field( array(
'name' => __( 'Color', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => 'cmb_color',
'type' => 'colorpicker',
) );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment