Add_meta_box not appearing, but does appear in screen options

I’m adding a meta box to a WordPress admin page.

It works fine on my local server but when I upload it to the live server, the meta box doesn’t appear.

Read More

Its does however appear in the screen options, so I know the code is working to some extent but it’s just not displaying anything on the edit page.

I’ve uninstalled all the plugins and that didn’t equally solve the issue.

Below is my code:

function ila_add_custom_box() {
    add_meta_box(
        'content-on-page',
        'Content On Page',
        'ila_render_meta_box',
        'page',
        'high'
    );
}

add_action( 'add_meta_boxes', 'ila_add_custom_box' );

function ila_render_meta_box() {
    echo "<h1>Edit Page Options</h1>";
}

How can I resolve it?

Related posts

2 comments

  1. You missed one argument in the $args for add_meta_box.

    The correct use would be (Codex):

    add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args );
    

    You forgot to set the context, add it and you should be fine.

    add_meta_box(
        'content-on-page',
        'Content On Page',
        'ila_render_meta_box',
        'page',
        'normal', // add this line
        'high'
    );
    
  2. The correct code

    $screens = array( 'post', 'page' )
        add_meta_box(
            'your_fields_meta_box', // $id
            'Your Fields', // $title
            'show_your_fields_meta_box', // $callback
            $screens , // $screen
            'normal', // $context
            'high' // $priority
        );
    

Comments are closed.