WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to add a meta box to all my pages (not posts) but it looks like I am only able to add it for a specific post based on the codex?

add_meta_box( $id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args = null );
share|improve this question
up vote 1 down vote accepted

Try this. This is part of some code I use.

 // Add meta boxes to Page
  add_meta_box( 'RelatedImage', __('Related images'), 'related_images_meta_box', 'page', 'normal', 'high' );

  function related_images_meta_box($object) { 
    $nonce = wp_create_nonce(plugin_basename( __FILE__ ));
    <input type="hidden" name="wp_filebrowser_nonce" id="wp_filebrowser_nonce" value="<?php echo $nonce; ?>" />
          <label for="related_image" class="">Related image</label>
          <input type="text" id="related_image" name="related_image"  value="<?php echo 'your meta property' ?>" size="40" />  
  <?php }
share|improve this answer
This only add to the "page" post type. – kaiser Mar 9 '12 at 2:01
Isn't that what the OP is asking for (to add a meta box to pages, but not to (blog) posts)? Or am I misreading the question? – Chip Bennett Mar 9 '12 at 2:10
@Steven...yup that's what I was asking for! – redconservatory Mar 9 '12 at 14:25

Wordpress has the following post types by default, with your custom post types add at the end of the array:

    [0] => post
    [1] => page
    [2] => attachment
    [3] => revision
    [4] => nav_menu_item
    [5] => ...all your custom post types

So you can loop through them and simply add a meta box to every post type. Note: This won't work for attachment, revision and nav_menu_item, so you want to skip them:

function wpse44962_add_meta_boxes()
    foreach ( array_keys( $GLOBALS['wp_post_types'] ) as $post_type )
        // Skip:
        if ( in_array( $post_type, array( 'attachment', 'revision', 'nav_menu_item' ) ) )

        // You'll have to set $id, $title, $callback yourself:
        add_meta_box( $id, $title, $callback, $post_type, 'advanced', 'default' );
add_action( 'add_meta_boxes', 'wpse44962_add_meta_boxes' );
share|improve this answer
thanks , exactly what I needed – paul Mar 23 '13 at 18:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.