Forked from j-mccarthy/register_cmb2_metabox_after_title.php
Created
December 15, 2017 02:27
-
-
Save yoclove/44c7884ab2ec0b8ef1453274e8205876 to your computer and use it in GitHub Desktop.
register cmb2 metabox after title on admin page edit screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function yourprefix_output_custom_mb_location() { | |
| cmb2_get_metabox( '_source_demo_metabox' ); | |
| } | |
| add_action( 'edit_form_after_title', 'yourprefix_output_custom_mb_location' ); | |
| add_action( 'cmb2_init', 'source_banner_metabox' ); | |
| /** | |
| * Hero/Banner for pages | |
| * | |
| * @see genesis_before_content | |
| * | |
| */ | |
| function source_banner_metabox() { | |
| // Start with an underscore to hide fields from custom fields list | |
| $prefix = '_source_demo_'; | |
| /** | |
| * Sample metabox to demonstrate each field type included | |
| */ | |
| $cmb_demo = new_cmb2_box( array( | |
| 'id' => $prefix . 'metabox', | |
| 'title' => __( 'Test Metabox', 'cmb2' ), | |
| 'object_types' => array( 'page' ), // Post type | |
| 'show_names' => true, // Show field names on the left | |
| ) ); | |
| $cmb_demo->add_field( array( | |
| 'name' => __( 'Test Text', 'cmb2' ), | |
| 'desc' => __( 'field description (optional)', 'cmb2' ), | |
| 'id' => $prefix . 'text', | |
| 'type' => 'text', | |
| ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment