WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question
function my_portfolio_meta_box_cb($post) {
     $template = get_post_meta($post->ID, '_wp_page_template', true);
     if ($template == 'portfolio.php') {

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

share|improve this answer
sorry for my english, how can we put this in a select option onchenge it meen that when qe choise the template the add_meta_box apear just in that moment. thanks h. – user5010 Apr 30 '11 at 17:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.