Option tree
How to Used Option Tree Plugin in Theme
Today I am going to describe am important topics for WordPress theme development. To WordPress theme back-end more user friendly the use of option tree is describable. Option tree is a popular WordPress framework which used in WordPress most seller premium theme ‘Avada’. Within four step I am describing “How to Used Option Tree Plugin in Your WordPress Theme”.
Fist step download Option Tree or Github and unzip the file. There have a folder as name “option-tree”, take it in your theme.
Second step need to call ot-loader.php in your theme functions.php from option-tree folder. Taking the below code in your theme functions.php
add_filter( 'ot_show_pages', '__return_false' ); add_filter( 'ot_show_new_layout', '__return_false' ); add_filter( 'ot_theme_mode', '__return_true' ); include_once( 'option-tree/ot-loader.php' );
Now you see Option Tree in your dashboard if you refresh. Here, include_once( ‘option-tree/ot-loader.php’ ); use for to call ot-loader.php from option-tree, use add_filter( ‘ot_show_pages’, ‘__return_false’ ); for show option tree demo in dashboard and use add_filter(‘ot_show_new_layout’, ‘__return_false’ ); & add_filter( ‘ot_theme_mode’, ‘__return_true’ ); to get option CSS and Scripts. Now you see theme options under dashboard Appearance.
Now to use option tree theme options or meta box need to ‘demo-theme-options.php’ & ‘demo-meta-boxes.php’ file in your functions.php. The both file get in option-treeassetstheme-mode copy or cut the file make a “inc” folder in your theme and paste it in inc folder. The both folder can rename as ‘theme-options.php’ & ‘meta-boxes.php’ and include both in your functions.php like:
include_once( 'inc/theme-options.php' ); include_once( 'inc/meta-boxes.php' );
How to Use Option Tree Meta Box
Delete all code from meta-boxes.php and taking below code in it.
<?php function custom_meta_boxes() { $unique_meta_box_name = array( 'id' => 'unique_meta_box_name', 'title' => __( 'Title Meta Box', 'theme-text-domain' ), 'desc' => '', 'pages' => array( 'pricing' ), //Here given post type where want to support 'context' => 'normal', 'priority' => 'high', 'fields' => array( array( 'label' => __( 'pricing_dollar', 'theme-text-domain' ), 'id' => 'meta_box_id', //This id for input date where want show 'desc' => 'Please input the Category name', 'type' => 'text' ), ) ); if ( function_exists( 'ot_register_meta_box' ) ) ot_register_meta_box( $unique_meta_box_name ); add_action( 'admin_init', 'custom_meta_boxes' ); ?>
Here, use unique_meta_box_name in three times, ‘pages’ => array( ‘pricing’ ), here pricing is a custom_post_type and ‘meta_box_id’ use unique this is important. Example given below how to use in HTML.
<?php $variables_name = get_post_meta($post->ID, 'meta_box_id', true); ?> <?php if($portfolio_category) :?> <div class="project-meta"><?php echo $variables_name; ?></div> <?php endif; ?>
The uses of Option tree theme option describe in next tune.
Comments are closed