Skip to content

Instantly share code, notes, and snippets.

@hirozed
Last active September 8, 2021 15:51
Show Gist options
  • Save hirozed/a008093807b307e0a99bb2b99f4693dd to your computer and use it in GitHub Desktop.
Save hirozed/a008093807b307e0a99bb2b99f4693dd to your computer and use it in GitHub Desktop.
WordPress CMB2 Base
<?php
/**
* Reason for CMB2 box
*/
function cmb2_admin_init() {
$prefix = 'add_prefix_here';
// Create the box.
$cmb2 = \new_cmb2_box(
array(
'id' => '[CHANGEME-id]',
'title' => __( '[CHANGEME-title]', '[CHANGEME-localization]' ),
'object_types' => array(
'page',
),
'context' => 'normal',
'priority' => 'default',
'show_names' => true,
'show_on' => array(
'key' => 'page-template',
'value' => array(
'page-templates/[CHANGEME-page-template].php',
),
),
)
);
// Add fields below.
}
add_action( 'cmb2_admin_init', __NAMESPACE__ . '\\cmb2_admin_init' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment