Vous cherchez un moyen de créer une colonne d’URL dans la bibliothèque de médias ? Ce snippet créera une nouvelle colonne dans la bibliothèque multimédia avec l’URL du fichier, ce qui vous permettra de copier et coller facilement l’URL.
Instructions:
Tout ce que vous avez à faire est d’ajouter ce code au fichier functions.php de votre thème ou dans un plugin spécifique à votre site:
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 );
Merci à Steve Taylor pour l’extrait original. Merci à Jurko Chervony pour les modifications suggérées.
Note : Si c’est la première fois que vous ajoutez des extraits de code dans WordPress, veuillez consulter notre guide sur la manière de copier/coller correctement des extraits de code dans WordPress, afin de ne pas casser accidentellement votre site.
Si vous avez aimé cet extrait de code, n’hésitez pas à consulter nos autres articles sur le site comme : 27 meilleurs thèmes WordPress pour votre site web et 15 meilleurs outils et plugins de marketing de contenu pour WordPress.
Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.
Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.
Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.
Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.
Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.
Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.
Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.
Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.
Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.
Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.
Thank you so much for sharing this. You just saved me a couple of hours and a bottle of Advil.
Thank you so much for this. Made a nifty little plugin for this!
Thank you so much for this. Made a nifty little plugin for this!
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.
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/
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.
man this is awesome! why this isn’t default in wordpress who knows. thanks a million!
Awesome! Thanks.
Thank you, thank you, thank you. I was going crazy with all the drilling down for urls. I really appreciate it!
So convenient. This should be a plugin… that gives me an idea!
oh maaaan you are the BOSSSS!!! Thanks!
Thanks! Exactly what I was looking for and saved me loads of clicking 🙂
Amazingly helpful snippet, thank you so much! makes my job worlds easier!
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.
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.
Fantastic. Thanks for this.
no problem glad you like the snippet.