CMB2 installation – cannot get it to work

I have followed the documentation on this page:
but cannot get it to work.

I have gone through other posts with the same issue and tried all of the suggestions and still nothing. This has left me confused onthe installation process.

Can someone confirm whether the following code is needed?

if ( file_exists( DIR . ‘/cmb2/init.php’ ) ) {
require_once DIR . ‘/cmb2/init.php’;
} elseif ( file_exists( DIR . ‘/CMB2/init.php’ ) ) {
require_once DIR . ‘/CMB2/init.php’;

and also whether the cmb2 folder should be installed in the theme folder or the plugin folder. Documentation says theme, installation page on wordpress says plugin.

Also where should the code from example_functions.php go? Should it be in the functions.php file in the theme folder?

I have installed the plugin via wordpress and therefore the folder is installed in the plugins folder. I have then copied and pasted all of the code from example_functions.php into my functions.php file within my theme folder. I have then added the below code to the page.php file in my theme folder.

$text = get_post_meta( get_the_ID(), ‘_cmb2_text’, true );
echo $text;

Please help.

Solutions Collecting From Web of "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', ),.


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)