Change meta box when the page’s template is changed

For my WordPress theme I have a custom portfolio post type and a portfolio page template to display them. What I want to do is add a meta box to the edit page area, but only when the page has the portfolio template.

Thanks.

Related posts

Leave a Reply

1 comment

  1. function my_portfolio_meta_box_cb($post) {
         $template = get_post_meta($post->ID, '_wp_page_template', true);
         if ($template == 'portfolio.php') {
             add_meta_box(........);
         }
    }
    

    Hook this via the register_meta_box_cb arg when registering the post type or in your manually via add_meta_boxes-portfolio hook.