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

I want to add add_meta_box to specific page type like Page Template, Like Product Template.

I am using this article http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/ to try it.

share|improve this question
up vote 2 down vote accepted

If your custom page template filename is foobar.php, you can use get_post_meta():

global $post;
if ( 'foobar.php' == get_post_meta( $post->ID, '_wp_page_template', true ) ) {
    // The current page has the foobar template assigned
    // do something

Personally, I like calling this inside my add_meta_boxes_page callback, and wrapping it around the add_meta_box() call itself.

function wpse82477_add_meta_boxes_page() {
    global $post;
    if ( 'foobar.php' == get_post_meta( $post->ID, '_wp_page_template', true ) ) {
        add_meta_box( $args );
add_action( 'add_meta_boxes_page', 'wpse82477_add_meta_boxes_page' );

You'll just need to instruct users to save the page after assigning the template, so that the meta box appears.

share|improve this answer
Thanks a lot, one prob here to inform user to save page once. BTW its saved ma lot time. Thanks CHIP – Ajay Patel Jan 21 '13 at 13:25

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.