Home / admin / Media library URL column for easy copy and paste
  • How to Media library URL column for easy copy and paste

    media-library-url-for-easy-copy-and-paste

    Add this snippet to the functions.php of your wordpress theme to create a new column with the original file URL. I have had a few projects in the past that required a client to copy and paste a files URL into a custom field or metabox this will just make life a little easier. Thanks to Steve Taylor for this snippet, I just expanded on it a little with the input field and onclick select.

    Thanks to Jurko Chervony for the suggested tweaks. ( click code to copy )

    wordpress snippet : PHP

    <>
    function muc_column( $cols ) {
    	$cols["media_url"] = "URL";
    	return $cols;
    }
    function muc_value( $column_name, $id ) {
    	if ( $column_name == "media_url" ) echo '<input type="text" width="100%" onclick="jQuery(this).select();" value="'. wp_get_attachment_url( $id ). '" />';
    }
    add_filter( 'manage_media_columns', 'muc_column' );
    add_action( 'manage_media_custom_column', 'muc_value', 10, 2 );
    

    ( WordPress codex functions, hooks, in this snippet. )

    wp_get_attachment_url, query, add_filter, add_action, _n, wp,
  • Fantastic. Thanks for this.

  • I don’t get it. Is the file’s URL already in the metabox or is it a blank metabox that you can enter a file’s URL into? How does this connect with the Media Library? Thanks.

    • This will place a input field with the column and a link to the file within it and when selected will auto select all the text within the field. This just saves a little time so you don’t have to go to the edit page to get the file URL.

  • Better variant http://pastebin.com/2i3TyQNR
    I added input width and fixed JS

    • Hi Jurko
      Yes I agree I should have done that with jQuery, ill add your updates to the snippet. Thanks for the input.

    • Thank Jurko Chervony I added your update and provided credit.

  • Amazingly helpful snippet, thank you so much! makes my job worlds easier!

  • Josh Howe

    Thanks! Exactly what I was looking for and saved me loads of clicking :)

  • Adam

    oh maaaan you are the BOSSSS!!! Thanks!

  • So convenient. This should be a plugin… that gives me an idea!

  • Shawn

    Thank you, thank you, thank you. I was going crazy with all the drilling down for urls. I really appreciate it!

  • Robin

    Awesome! Thanks.

  • Cory Church

    man this is awesome! why this isn’t default in wordpress who knows. thanks a million!

  • Hi Brent,

    This may be good for some, just not sure its a great feature for everyone. Thanks for the feedback its great to hear what I’m posting is helping people.

  • Arthur Becker

    I copied and pasted it at the very bottom of the ‘functions.php’ file, and when I tried to open the website again, it gave me a fatal error. Any ideas why? I’m using wordpress 3.8.

  • Justin

    Thank you so much for this. Made a nifty little plugin for this!

  • Justin

    Thank you so much for this. Made a nifty little plugin for this!

  • Rob

    Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.

  • Rob

    Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.

  • Rob

    Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.

  • Rob

    Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.

  • Rob

    Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.

  • Rob

    Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.

  • Rob

    Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.

  • Rob

    Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.

  • Rob

    Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.

  • Rob

    Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.

  • Rob

    Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.

  • Pingback: How To Add URL Column To WordPress Media Library?()

  • Oseghale Ibhawoh

    Works perfectly. Many thanks man!

  • Sir_Rah

    Was looking all morning for something like this….Thanks

  • Julian Kingman

    Awesome. I was looking for a plugin, but this is way easier and is now rolled into my child theme (and future child themes). Thanks!