1

I am using the following code in functions.php for adding a custom meta box.

The custom post type is themes. I want to add more post types, how can I?

add_meta_box( 
    'my-meta-box-id', 
    'Demo & Download', 
    'cd_meta_box_cb', 
    'themes', 
    'normal', 
    'high' 
);
  • Do you want to add more Custom Post Types or add the same metabox to other post types? – brasofilo Dec 11 '12 at 2:43
  • I want to add same meta box to other post types too. – Allen Dec 11 '12 at 2:45
3

Whenever in doubt about a WordPress function, consult the Codex.
http://codex.wordpress.org/Function_Reference/add_meta_box

There, you'll see that you need to add one meta box to each post type.

add_action( 'add_meta_boxes', 'myplugin_add_custom_box' );

function myplugin_add_custom_box() {
    add_meta_box( 
        'myplugin_sectionid',
        __( 'My Post Section Title', 'myplugin_textdomain' ),
        'myplugin_inner_custom_box',
        'post' 
    );
    add_meta_box(
        'myplugin_sectionid',
        __( 'My Post Section Title', 'myplugin_textdomain' ), 
        'myplugin_inner_custom_box',
        'page'
    );
}

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.