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

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!

share|improve this question
up vote 5 down vote accepted

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 */ );
share|improve this answer
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 '11 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. – goldenapples Apr 15 '11 at 1:06
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 '11 at 12:50

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.