X

How To Create a Media Library URL Column for Easy Copying and Pasting

Snippets by IsItWP

Are you looking for a way to create a Media Library URL column? This snippet will create a new column in the Media Library with the file URL that will allow you to easily copy and paste the URL.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

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 );

Thanks to Steve Taylor for the original snippet. Thanks to Jurko Chervony for suggested tweaks.

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 27 best WordPress business themes for your website and 15 best content marketing tools and plugins for WordPress.

Comments   Leave a Reply

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

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

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

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

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

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

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

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

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

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

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

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

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

  14. 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.

    1. Without taking a look at your functions.php I would not be sure what the issue was. You could put it on pastebin.com and use the contact form to send me the link so i can take a look at it.

      http://wpsnipp.com/index.php/contact/

  15. 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.

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

  17. Awesome! Thanks.

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

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

  20. oh maaaan you are the BOSSSS!!! Thanks!

  21. Thanks! Exactly what I was looking for and saved me loads of clicking 🙂

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

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

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

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

  24. 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.

    1. 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.

  25. Fantastic. Thanks for this.

    1. no problem glad you like the snippet.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!