简体   繁体   中英

WordPress : how to add an image upload button to the edit form?

I want to add an image upload button to the WordPress edit form and retrieve the ID of the uploaded media.

If it is possible, I want the user to click the button, choose his image on his computer and then display a tag containing the ID of the media in the textarea. Do you know a way to do that?

Thanks

I found by myself how to add and use a media button. If someone else is searching for that, I wrote a tutorial about doing this on SitePoint . You can also find a French version on my blog .

Basically, it uses the action media_buttons which is currently not listed on the WordPress Codex. This action is called when media buttons are displayed in the WordPress editor: all you have to do is displaying your own button with a dedicated function.

Then, you can open a media window and retrieve the user's selection thanks to a good (but hidden!) API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM