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 be able to add a metabox to a new submenu page that I have created. I have the following basic code which I was hoping would work but it seems not to:

add_action("init", "my_register_post_types");
function my_register_post_types()
    register_post_type("my-cpt", array(
        "label" => "My CPT",
        "public" => true

add_action("admin_menu", "my_add_menu_items");
function my_add_menu_items()
    add_submenu_page("edit.php?post_type=my-cpt", "Test Page", "Test Page", "edit_posts", "my-cpt-slug", "display_my_test_page");
    //return value from this is my-cpt_page_my-cpt-slug

function display_my_test_page()
    do_meta_boxes("my-cpt", "normal", null);

add_action("add_meta_boxes", "my_add_metaboxes");
function my_add_metaboxes()
    add_meta_box("my-cpt-metabox", "My CPT Metabox", "display_my_metabox", "my-cpt_page_my-cpt-slug", "normal", "core");

function display_my_metabox()
    echo "Hello";

According to http://shibashake.com/wordpress-theme/standard-wordpress-metabox, I should be using the return value of add_submenu_page to be used in the add_meta_box function in place of a CPT slug.

I was hoping that the the metabox would appear on the new "Test Page" but no joy. Any ideas? Am I missing something?

share|improve this question
up vote 1 down vote accepted

The add_meta_boxes hooks load in edit-form-advanced.php. Your custom plugin page "test" does not use that file. You need to hook into the "plugin admin page hooks" instead.

Secondly, the third parameter of add_meta_box is just the CPT slug, not the page slug you have.

Here is what you need to change:

add_action("load-my-cpt_page_my-cpt-slug", "my_add_metaboxes");
function my_add_metaboxes()
    add_meta_box("my-cpt-metabox", "My CPT Metabox", "display_my_metabox", "my-cpt", "normal", "core");
share|improve this answer
Fantastic! Thank you very much indeed! :) – Tim Smith Aug 17 '13 at 18:32
Asking a little late, the action hook is triggered but my metabox callback doesn't seem to work. Any reasons? – Rutwick Gangurde Jun 1 '15 at 14:23
@RutwickGangurde : sorry, no idea, but if you would ask a new question and include your code maybe I, or someone, could help. – s_ha_dum Jun 1 '15 at 14:36
Thanks. I will do that! – Rutwick Gangurde Jun 1 '15 at 14:38
I had to do do_meta_boxes call! – Rutwick Gangurde Jun 2 '15 at 11: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.