I am successfully using get_current_screen(); to get the post_type to decide whether to manipulate a meta box or not.

I also need to use it in:

add_action('admin_menu', 'infographicMetaBox');

function infographicMetaBox() {
    // ...
    $screen = get_current_screen();
    if('post' != $screen->post_type)
    // ...

however it doesn't seem to be available in that hook function (maybe being called to early?).


I don't know exactly what you are trying to accomplish but you seem to be dealing with meta boxes. If so there are a number of meta box specific hooks.

do_action('add_meta_boxes', $post_type, $post);
do_action('add_meta_boxes_' . $post_type, $post);

do_action('do_meta_boxes', $post_type, 'normal', $post);
do_action('do_meta_boxes', $post_type, 'advanced', $post);
do_action('do_meta_boxes', $post_type, 'side', $post);


As well as the admin_head* hooks



All of which run after global $current_screen is set here: http://core.trac.wordpress.org/browser/tags/3.5.1/wp-admin/admin-header.php#L18

  • admin_head hook seems to be working great for this. Thank you very much!! – Titan Jun 5 '13 at 7:26

Yes, it is too early. Check http://codex.wordpress.org/Function_Reference/get_current_screen for examples of usage.

  • What are my options then? I have code to query a database to populate a metabox, but I only want it happening on the main post new/edit screens instead of making a wasteful db call every page load. – Titan Jun 4 '13 at 18:13
  • You can hook your function to anything that comes after admin_init. Perhaps admin_head would work. Here's a (probably incomplete) list of actions run during an Admin page load. – Pat J Jun 4 '13 at 18:35
  • 1
    Hook your function to edit_post. Function will have one parameter $id which is post_id. Use get_post_type( $id ) to determine post's type and go from there. – Frank P. Walentynowicz Jun 4 '13 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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