Skip to content
mattheu edited this page Apr 27, 2013 · 15 revisions

To add your own meta boxes, use the 'cmb_meta_boxes' filter to add your own meta box to the array of meta boxes.

Each meta box can be created by passing an array of setting. See available arguments listed below.

Available Args

  • id (string) (required) HTML 'id' attribute of the meta box.
  • title (string) (required) Title of the edit screen section, visible to user
  • fields (array) (required) An array of fields that will be added to the meta box.
  • pages (string) (required) The type of Write screen on which to show the meta box (eg 'post', 'page')
  • show_on (array) (optional) Further restrict where a meta box is shown. An array of key => value where key is what you are restricting by. Available restrictions are id and page-template. ID expects a numeric value or array of values. Page Template expects a string; the filename of the template.
  • context (string) (optional) The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side'). Default: 'advanced'
  • priority (string) (optional) The priority within the context where the boxes should show ('high', 'core', 'default' or 'low')

Example Code

add_filter( 'cmb_meta_boxes', 'cmb_sample_metaboxes' );

function cmb_sample_metaboxes( array $meta_boxes ) {
	
	$meta_boxes[] = array(
		'title' => 'CMB Test - all fields',
		'pages' => 'page',
		'show_on' => array( 'id' => array( 1 ) );
		'context'    => 'normal',
		'priority'   => 'high',
		'fields' => $fields // an array of fields - see individual field documentation.
	);

	return $meta_boxes; 

}