CMB2 installation – cannot get it to work

Step#1: Using git clone the latest CMB2 resources to your working project.
Step#2: Rename the CMB2-master (or anything else) folder to cmb.
Step#3: In your project’s functions.php simply use the following code:

if( !class_exists("CMB2") ){
    require_once( dirname(__FILE__)."/libs/cmb/init.php" );
}

(I put all my external libraries to /themes/my-theme/libs/ so I called it so)

Step#4: You can include the example-functions.php from the cmb folder to check whether it’s working or not. Simply use the following code in your functions.php:

require_once ( get_template_directory() . '/libs/cmb/example-functions.php' );

if it works then you will see example meta boxes in Add New Page, because by default it’s coded like that: 'object_types' => array( 'page', ),.

Alternatively

Step#1: Install the CMB2 plugin from the WordPress plugin repository
Step#2: Browse the wp-content/plugins/cmb2/ (I can’t remember the plugin folder name), and copy the example-functions.php to your theme for testing.
Step#2: Simply use the following code in your functions.php to add the file:

require_once ( get_template_directory() . '/example-functions.php' );

If it works in Add New Page, you can do your own job. 🙂


For your custom usage just copy the function (cmb2_sample_metaboxes()) from the example and use the filter cmb2_meta_boxes. You can follow the example-functions.php completely. (In my installation it’s in line#36 – see here)