WordPress custom metabox for a specific page

Is there a way to add a metabox for a specific page, I want the metabox to be displayed only on the page “X” in the admin, is there an argument or something that you can specify in order to achive this?

Related posts

Leave a Reply

1 comment

  1. I use the excellent Core Metabox Library for this purpose. Its really easy to implement, and can do pretty much anything as far as I can tell.

    This is from the relevant GitHub wiki page:

        $meta_boxes[] = array(
            'id' => 'contact-information',
            'title' => 'Contact Information',
            'pages' => array('page'), // post type
            'show_on' => array( 'key' => 'id', 'value' => array( 50, 24 ) ),
            'context' => 'normal', //  'normal', 'advanced', or 'side'
            'priority' => 'high',  //  'high', 'core', 'default' or 'low'
            'show_names' => true, // Show field names on the left
            'fields' => array(
    

    The type of show_on filter (key) is “id” and the value for that filter is an array of your IDs. If you only wanted it on the About page you could use ‘value’ => 50 instead of putting it in an array.

    If you don’t want to use the library, you could find more clues by having a look inside: on line 100 of init.php of the library, it does something like:

        if( conditions_met() )
            add_meta_box( params ) ;
    

    (Seriously, though – just use it all – it does uploads, tinymce, taxonomies, the works!)

    Hope that Helps!
    Tim