Is there an easy way to include an upload box to your settings page?
I am building an Open Graph options page and I like users to upload a standard image directly from that page.
Is there an easy way to include an upload box to your settings page?
I am building an Open Graph options page and I like users to upload a standard image directly from that page.
You must be logged in to post a comment.
WordPress provides a convenient function for just this purpose:
wp_handle_upload()
.Assuming that you already have the appropriate file form field in your settings page, and that you’re using
register_setting()
for your options, and therefore already have an options validation callback, simply handle the file form field data usingwp_handle_upload()
. Here’s an example:Then, you just need to define that
theme-slug_image_upload()
callback, usingwp_handle_upload()
:That’s pretty much it.