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 );

2 Answers 2


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 }
  • This only add to the "page" post type.
    – kaiser
    Mar 9, 2012 at 2:01
  • 2
    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? Mar 9, 2012 at 2:10
  • @Steven...yup that's what I was asking for! Mar 9, 2012 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' );

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.