wordpress snippets last updated   : January 29, 2015
we now have 646 snippets

Media library admin columns with attachment id

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will add a new column within the media library admin columns with the attachment id.

snippet :  PHPcopy
add_filter('manage_media_columns', 'posts_columns_attachment_id', 1);
add_action('manage_media_custom_column', 'posts_custom_columns_attachment_id', 1, 2);
function posts_columns_attachment_id($defaults){
    $defaults['wps_post_attachments_id'] = __('ID');
    return $defaults;
function posts_custom_columns_attachment_id($column_name, $id){
	if($column_name === 'wps_post_attachments_id'){
	echo $id;

Did you like this post? If so please share it with your friends. Thanks!

  • David

    This makes it MUCH easier to get the id. Would it be possible to add this column to the gallery tab on the media insert pop-over panel as well? (so you could easily see the id of an image for include or exclude in the shortcode)

    • http://wpsnipp.com Kevin Chard

      Hi David,
      I’m sure you could not something I have looked into, I do a little research for a future posting.

  • http://www.facebook.com/people/Brandon-Wilds/100002403706728 Brandon Wilds

    I am currently trying to get the attachment id to show in a custom field within my media library and cannot seem to figure out how to get it there. ┬áIts easy to add to the media page itself using the $_REQUEST[‘attachment_id’] although this does not work in the media library.

    Your code above does not seem to work within my theme for whatever reason.

  • DaveN

    Any way to make the column sortable in 3.5?

  • Jana

    Thank you so much, you saved me hours and hours ;)

  • Eva Collados Pascual

    Thanks Kevin! Worked perfectly for me. I tried other functions for this i’ve found on the web without you results.

    Addicted to your snippets!