Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save azizultex/18bdaefdf867b31e7f36 to your computer and use it in GitHub Desktop.
Save azizultex/18bdaefdf867b31e7f36 to your computer and use it in GitHub Desktop.
Add Option Tree Metabox to Specific Page Template Only
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
$template_file = get_post_meta($post_id, '_wp_page_template', TRUE);
if ($template_file == 'welcome.php') {
ot_register_meta_box( $home_page_meta_box );
}
/* -------------------------------------------------------------
so, entire file should looks like this:
------------------------------------------------------------- */
<?php
/**
* Initialize the meta boxes.
*/
add_action( 'admin_init', '_custom_meta_boxes' );
/**
* Meta Boxes demo code.
*
* You can find all the available option types
* in demo-theme-options.php.
*
* @return void
*
* @access private
* @since 2.0
*/
function _custom_meta_boxes() {
/**
* Create a custom meta boxes array that we pass to
* the OptionTree Meta Box API Class.
*/
$header_image = array(
'id' => 'header_overlay_content',
'title' => 'Header Content',
'pages' => array( 'page'),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'label' => 'Header Area',
'id' => 'header_content_overlay',
'type' => 'textarea',
)
)
);
/**
* Register our meta boxes using the
* ot_register_meta_box() function.
*/
ot_register_meta_box( $header_image );
$home_page_meta_box = array(
'id' => 'home_setting',
'title' => 'Home Page Content',
'desc' => '',
'pages' => array( 'page' ),
'context' => 'normal',
'fields' => array(
array(
'label' => 'Location',
'id' => 'location',
'type' => 'text',
'desc' => '',
'std' => '',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'class' => ''
),
array(
'label' => 'Registration Link',
'id' => 'register_link',
'type' => 'text',
'desc' => '',
'std' => '',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'class' => ''
),
array(
'label' => 'Banner Image Link',
'id' => 'banner_img',
'type' => 'upload',
'desc' => '',
'std' => '',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'class' => ''
),
array(
'label' => 'Left Column Content',
'id' => 'left_c',
'type' => 'textarea',
'desc' => '',
'std' => '',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'class' => ''
),
array(
'label' => 'Center Column Content',
'id' => 'center_c',
'type' => 'textarea',
'desc' => '',
'std' => '',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'class' => ''
),
array(
'label' => 'Right Column Content',
'id' => 'right_c',
'type' => 'textarea',
'desc' => '',
'std' => '',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'class' => ''
)
)
);
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
$template_file = get_post_meta($post_id, '_wp_page_template', TRUE);
if ($template_file == 'welcome.php') {
ot_register_meta_box( $home_page_meta_box );
}
}
@makwanakalpesh1
Copy link

what is this

@sky4git
Copy link

sky4git commented May 18, 2015

Isn't this code gives error in dashboard on debug mode?
at least that's what happening to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment