CMB Custom Metaboxes
Custom Metaboxes and Fields WordPress Uses
To make wordpress theme user friendly admin penal we are use some framework like option tree, SMOF, Redux etc. Custom Metaboxes and Fields WordPress is also a popular framework for metaboxes awesome UI. This framework can use alternative of option tree metaboxes. In this tune I going to show how to use the framework in your wordpress theme metaboxes.
Step-1: Download Custom Metaboxes and Fields for WordPress from Github .
Step-2: Create a folder in your theme can use any name(Suppose folder name “cmb” ) . From download zip take all file into your folder(In cmb folder).
Step-3: Now you need to include init.php file in your theme functions.php file. Use below function in your theme functions.php
// Initialize the metabox class add_action( 'init', 'be_initialize_cmb_meta_boxes', 9999 ); function be_initialize_cmb_meta_boxes() { if ( !class_exists( 'cmb_Meta_Box' ) ) { require_once( 'lib/metabox/init.php' ); } }
Step-4: Use function for Metaboxes UI in your theme functions.php file. Here you need to change id, post type and field type. For more help see example-functions.php
function be_sample_metaboxes( $meta_boxes ) { $prefix = '_cmb_'; // Prefix for all fields $meta_boxes['test_metabox'] = array( 'id' => 'test_metabox', 'title' => 'Test Metabox', 'pages' => array('page'), // post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left 'fields' => array( array( 'name' => 'Test Text', 'desc' => 'field description (optional)', 'id' => $prefix . 'test_text', 'type' => 'text' ), ), ); return $meta_boxes; } add_filter( 'cmb_meta_boxes', 'be_sample_metaboxes' ); Step-5: To display metadata use below code. <?php global $post; $text = get_post_meta( $post->ID, '_cmb_test_text', true ); echo $text; ?>
Wanna I want show you how to I am using.
By using different field type (can also help from example-functions.php) and display option everyone can use the metaboxes framework. For more help see documentation. If faced any problem to use the Custom Metaboxes and Fields WordPress comment here.
Comments are closed