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 want to use attachment IDs for shortcodes, but if the image is published with a permalink, it's harder to find the ID.

I've found some functions online that can turn the attachment url into its ID, but that's ridiculous if I have to use a function every time I want to use the shortcode in my posts.

Trying to do: [stuff include="1,4,55"]

Instead of: [stuff include="http://www.example.com/wp-content/uploads/etc..."]

share|improve this question
up vote 1 down vote accepted

You could hook into 'attachment_fields_to_edit' and just add a row:

<?php # -*- coding: utf-8 -*-
 * Plugin Name: T5 Show Attachment ID
 * Version:     2012.06.04
 * Author:      Thomas Scholz <info@toscho.de>
 * Author URI:  http://toscho.de
 * License:     MIT
 * License URI: http://www.opensource.org/licenses/mit-license.php

if ( ! function_exists( 't5_show_attachment_id' ) )
    add_filter( 'attachment_fields_to_edit', 't5_show_attachment_id', 10, 2 );

    function t5_show_attachment_id( $form_fields, $post )
        $form_fields['t5_id'] = array (
                'label'      => 'ID',
                'input'      => 'html',
                'html'       => "<strong>$post->ID</strong>",
        return $form_fields;


enter image description here

share|improve this answer

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.