Toggle admin metabox based upon chosen page template
Rather than rendering the metabox only to hide it with jQuery you can use this. The only difference being that the hiding/showing of the metabox requires selecting ‘Update’ after changing the drop-down field.
1 2 3 4 5 6 7 8 9 10 11 12 | function add_meta_box() { global $post; if(!empty($post)) { $pageTemplate = get_post_meta($post->ID, '_wp_page_template', true); if($pageTemplate == 'your-page-template-here.php' ) { add_meta_box( $id, $title, $callback, 'page', $context, $priority, $callback_args ); } } } add_action( 'add_meta_boxes', 'add_meta_box' ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.