image ID in Media Library

Column with the image ID in Media Library is very useful for every developer or author who is managing posts and images. By default our Media library looks like that in the list view:

What we want to achieve is to have the additional column with ID for every image:

Let’s go to work. Add below code to your funtions.php file in the root of your theme.

if ( ! function_exists( 'wpi_media_library_column_id' ) ) {
    /**
     * Add Item ID column in Media Manager
     */
    function wpi_media_library_column_id( $columns ) {
        $columns['colID'] = esc_html__( 'ID', 'wpi-lang' );

        return $columns;
    }
}
add_filter( 'manage_media_columns', 'wpi_media_library_column_id' );

if ( ! function_exists( 'wpi_media_library_column_id_row' ) ) {
    /**
     * Add ID for item in Media Manager
     */
    function wpi_media_library_column_id_row( $columnName, $columnID ) {
        if ( $columnName == 'colID' ) {
            echo $columnID;
        }
    }
}
add_filter( 'manage_media_custom_column', 'wpi_media_library_column_id_row', 10, 2 );

The first part adds ID column in Media Library, the second display’s ID for every image. That’s it, So easy 🙂

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *