admin管理员组

文章数量:1122846

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

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 asked Jun 3, 2012 at 19:09 gavsiugavsiu 2132 silver badges13 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 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:

本文标签: permalinksIs there a way to show attachment IDs on the attachment info screen