Skip to content

Instantly share code, notes, and snippets.

@j-mccarthy
Last active December 15, 2017 02:27
Show Gist options
  • Save j-mccarthy/2714caead6471843abfb to your computer and use it in GitHub Desktop.
Save j-mccarthy/2714caead6471843abfb to your computer and use it in GitHub Desktop.
register cmb2 metabox after title on admin page edit screen
<?php
add_action( 'cmb2_init', 'source_banner_metabox' );
function source_banner_metabox() {
$prefix = '_source_demo_';
$cmb_demo = new_cmb2_box( array(
'id' => $prefix . 'metabox',
'title' => __( 'Test Metabox', 'cmb2' ), // Kept this as I don't want to remove the metabox wrap
'object_types' => array( 'page' ),
'show_names' => true,
) );
$cmb_demo->add_field( array(
'name' => __( 'Test Text', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'text',
'type' => 'text',
) );
}
function source_output_custom_mb_location() {
cmb2_get_metabox( '_source_demo_metabox' )->show_form();
}
add_action( 'edit_form_after_title', 'source_output_custom_mb_location' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment