# Adding Custom Metaboxes to Custom Pages

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
));
}

{
//return value from this is my-cpt_page_my-cpt-slug
}

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

{
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?

-

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");
{
add_meta_box("my-cpt-metabox", "My CPT Metabox", "display_my_metabox", "my-cpt", "normal", "core");
}

-
Fantastic! Thank you very much indeed! :) –  Tim Smith Aug 17 '13 at 18:32