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

On the front-end, I'm using a query to show all attachments attached to the current post. However, on the compose page, there's no way for a user to see how many images are attached without opening up the media gallery.

I would like to add a meta box (or something) to display the current number of attached images – perhaps something like this: http://cl.ly/image/0a2q171v3y2u

Is this possible?


share|improve this question
up vote 2 down vote accepted
add_action( 'add_meta_boxes', 'attached_images_meta' );

function attached_images_meta() {
    $screens = array( 'post', 'page' ); //add more in here as you see fit
    foreach ($screens as $screen) {
            'attached_images_meta_box', //this is the id of the box
            'Attached Images', //this is the title
            'attached_images_meta_box', //the callback
            $screen, //the post type
            'side' //the placement
function attached_images_meta_box($post){
    $args = array('post_type'=>'attachment','post_parent'=>$post->ID);
    $count = count(get_children($args));
    echo '<a href="#" class="button insert-media add_media" data-editor="content">'.$count.' Images</a>';

The above will link to the media uploader. I added the link because the screenshot you posted looked like a link. Feel free to remove the link like so:

echo $count.' Images';

Just pop this in your functions.php, custom plugin, etc.

share|improve this answer
Perfect, thanks Josh! – mattisahuman Feb 17 '13 at 1:19

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.