How to Add Images to Media Library after Uploading them in PHP Programmatically phần 3 (ok)
https://rudrastyh.com/wordpress/how-to-add-images-to-media-library-from-uploaded-files-programmatically.html
Last updated
Was this helpful?
https://rudrastyh.com/wordpress/how-to-add-images-to-media-library-from-uploaded-files-programmatically.html
Last updated
Was this helpful?
When you upload files from WordPress admin area, they will automatically appear in Media > Library. But what if you want to create a custom file uploader specially for your website visitors?
What is important to remember here?
I placed the PHP file process_upload.php
into the theme directory, if you would like to move it to the other location, do not forget to make changes in the next piece of code on line 4 (I mean code in Step 2).
The form must have enctype="multipart/form-data"
attribute. Many forget about it.
You can also create a shortcode for this form, just insert this to the functions.php
:
Now you can use just [misha_uploader]
in the editor.
This is process_upload.php
file that I decided to create in my current theme directory.
Optionally we can set the third parameter of the wp_insert_attachment()
as a parent post ID, and set the featured image of this post with set_post_thumbnail()
.
It is easier to organize your uploaded images from WordPress Media Library. All the photos on the screenshot are taken by me in Roza Khutor resort.