Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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

Result:

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

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.