I am trying to show a certain metabox only on a certain template. I have tried putting this code in my functions.php file:
add_filter('rwmb_meta_boxes', 'main_page_register_meta_boxes' );
function main_page_register_meta_boxes( $meta_boxes ) {
$prefix = '';
remove_post_type_support('page', 'editor');
$meta_boxes[] = [
'title' => esc_html__( 'Header', 'Header' ),
'id' => 'Header_section_1',
'post_types' => ['page'],
'context' => 'normal',
'include' => array(
'template' => array( 'content-mainPage.php' ),
),
'fields' => [
[
'type' => 'text',
'name' => esc_html__( 'title', 'title' ),
'id' => $prefix . 'title',
],
[
'type' => 'wysiwyg',
'name' => esc_html__( 'Description', 'Description' ),
'id' => $prefix . 'Description',
],
],
];
return $meta_boxes;
}
I found a solution that adds a display condition for a specific page template but it doesn't work in my case
'include' => array(
'template' => array( 'content-mainPage.php' ),
),
The still created metabox is displayed when editing each page.
Does anyone know how to create a metabox that will be assigned to a specific Wordpress page template?