Is there an explicit action hook that will fire when (or just before) the admin Edit page renders for a custom post type? Something similar to {$new_status}_{$post->post_type}?

I'm trying to find the least obtrusive place to insert my add_meta_box() registration so that it's not calling that function on every page refresh, but only when it's needed (ie: the user wants to create a new custom post or edit an existing custom post).

Thanks for your thoughts / code snippets!

1 Answer 1


register_post_type() has a registration option called 'register_meta_box_cb'. Set that to a valid callback and it will call that function only when it is compiling the meta boxes for that post type's edit screen. Something like this:

register_post_type( 'foo', array(
  'public' => true,
  'label' => 'foo',
  'register_meta_box_cb' => 'bar',

function bar(){
  add_meta_box('blah', 'blah', /* etc */ );
  • Bloody outstanding! I missed that one. Your answer fits my requirements exactly! But, going back to my original question, IS there some way to hook into when the Edit page is invoked? I even tried edit_post and that didn't seem to fire under any circumstance (even for posts!)
    – Tom Auger
    Apr 14, 2011 at 21:29
  • Try 'admin_head-edit.php' if you want your code to fire on the edit.php page itself. 'save_post' and 'edit_post' fire on saving changes (including auto-drafts) to a post. Apr 15, 2011 at 1:06
  • 3
    The method John posted is the proper way of adding metaboxes to a particular post type, beyond that method the alternative is to register metaboxes on the add_meta_boxes or add_meta_boxes-$type action(those actions exist specifically for metabox registration).
    – t31os
    Apr 15, 2011 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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