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

The current method for adding your own meta boxes is to use the 'cmb_meta_boxes' filter to add your own meta box to the array of meta boxes.

Note that A change is planned that will make this process simpler, although backwards compatability will be maintained.

Each meta box can be created by using the 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
  • pages (string) (required) The type of Write screen on which to show the meta box (eg 'post', 'page')
  • fields (array) (required) An array of fields that will be added to the meta box.
  • 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' => 'post',
		'context'    => 'normal',
		'priority'   => 'high',
		'fields' => $fields // an array of fields - see individual field documentation.
	);

	return $meta_boxes; 

}