1

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.

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?

4

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'
);
0

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
    );
  • 1
    Why is this the correct code? A good answer includes a good explanation. – butlerblog Aug 11 '19 at 11:59

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.