0

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..."]

0

1 Answer 1

2

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:      Fuxia Scholz
 * 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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