I've created this page:

function wpdocs_register_my_setting() {
        'View Tasks',
        'View Tasks',

function view_tasks_submenu_page_callback() {
    // html
add_action( 'admin_menu', 'wpdocs_register_my_setting' );

And I want to add a meta box to this page only.

function cd_meta_box_add() {
    add_meta_box( 'in-progress-metabox', 'In Progress', 'render_task_in_progress_metabox', 'task', 'normal', 'high' );
function render_task_in_progress_metabox() {
    // html
add_action( 'add_meta_boxes', 'cd_meta_box_add' );

But I cannot seem to find the correct answer for this. Again, I only want to add this meta box to this specific page. I've seen people talk about needing to use do_meta_boxes but it doesn't really make sense.

  • please complete your code, how do you create your page? – Jevuska Apr 16 '16 at 1:42
  • What? The code is complete... you don't need to see the HTML output of the actual page.... that has nothing to do with my question. – dcolumbus Apr 16 '16 at 15:27
  • 1
    @dcolumbu, from your snippet and explanation it is not very obvious when do you want to add it and when not. – Mark Kaplun Apr 16 '16 at 16:46
  • I think it's extremely obvious. I've created an admin page and I want to add a meta box to that page only... I shown the code for both the page and the meta box, but I don't know how to accomplish it. – dcolumbus Apr 19 '16 at 15:40

I think for this you want to go with Wordpress Setting API.

If you prefer meta box. You have to add a do_action in your function which render the page (view_tasks_submenu_page_callback).

do_action( 'add_meta_boxes', $hook_id );

And add do_meta_boxes($hook_id, $context, null) where you want your meta boxes appear.

replace $hook_id by the fourth parameter of add_meta_box function.

| improve this answer | |
  • But there is no ID given for this page. – dcolumbus Apr 19 '16 at 15:41
  • I edited the answer for more clear. – Tung Du Apr 19 '16 at 15:47

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.