how to add a meta box to wordpress pages

后端 未结 1 1662
伪装坚强ぢ
伪装坚强ぢ 2021-01-04 21:53

i want to make this code for pages

add_action( \'add_meta_boxes\', \'meta_box_video\' );
function meta_box_video()
{
    add_meta_box( \'video-meta-box-id\',         


        
1条回答
  •  孤街浪徒
    2021-01-04 22:23

    This:

    function meta_box_video()
    {
        add_meta_box( 'video-meta-box-id', 'Video Embed', 'meta_box_callback', 'post', 'normal', 'high' );
    }
    

    Should specify page not post.

    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
    }
    

    Take a look at the Codex for add_meta_box(). The examples are very helpful. The portion you are interested in is under "Parameter". The fourth parameter allows you to specify whether you want the metabox on pages, posts, etc.

    0 讨论(0)
提交回复
热议问题