Add Metaboxes To Your Plugins With CMB

Example plugin on Github

I posted the example plugin on Github. Download it and play around locally to see how easy it actually is. See my note above that the example-functions.php file must be includes after the init.php file. This is because the example functions file hooks into the cmb_meta_boxes action and that is fired from the init.php file, so if you included it after init.php then nothing would happen! This happened to me at first so please take note!

Adding your own metaboxes

CMB comes with dozens of field types including datepickers, colour pickers and WYSIWYGs. You also add metaboxes by simply creating an array that CMB understands. From their documentation:

<?php function be_sample_metaboxes( $meta_boxes ) { 	$prefix = '_cmb_'; // Prefix for all fields 	$meta_boxes[] = array( 		'id' => 'test_metabox',
		'title' => 'Test Metabox',
		'pages' => array('page'), // post type
		'context' => 'normal',
		'priority' => 'high',
		'show_names' => true, // Show field names on the left
		'fields' => array(
				'name' => 'Test Text',
				'desc' => 'field description (optional)',
				'id' => $prefix . 'test_text',
				'type' => 'text'
	return $meta_boxes;
add_filter( 'cmb_meta_boxes', 'be_sample_metaboxes' );