Run
Run

Reputation: 57176

Wordpress meta-box - How to add meta-box to pages?

How can I add meta-box to pages and posts?

I have this code added to themes/package/demo.php, and that I can see Standard Fields and Advanced Fields in my posts, but I only see Standard Fields in pages.

Can I have Advanced Fields in pages as well?

There is an answer here, but where should I put this script below?

function meta_box_video()
{                                      // --- Parameters: ---
    add_meta_box( 'video-meta-box-id', // ID attribute of metabox
                  'Video Embed',       // Title of metabox visible to user
                  'meta_box_callback', // Function that prints box in wp-admin
                  'page',              // Show box for posts, pages, custom, etc.
                  'normal',            // Where on the page to show the box
                  'high' );            // Priority of box in display order
}

Upvotes: 0

Views: 2055

Answers (1)

CaioVncius
CaioVncius

Reputation: 337

Use this code:

function myplugin_add_meta_box() {

$screens = array( 'post', 'page' );

foreach ( $screens as $screen ) {

    add_meta_box(
        'myplugin_sectionid',
        __( 'My Post Section Title', 'myplugin_textdomain' ),
        'myplugin_meta_box_callback',
        $screen
    );
}
} add_action( 'add_meta_boxes', 'myplugin_add_meta_box' );

Upvotes: 1

Related Questions