0

I am currently customizing a Wordpress Theme, and I want to add a new form field on Category for uploading an image. The image should be retrieved from the Media Library.

I found out that there are ways to do this, but I am not sure which one is the best practice or the recommended approach.

Thank you in advance for your help.

  • Depending on your requirements, you could use Advanced Custom Fields. If you can't have a dependency on ACF in your theme, you could have a look at this older article – Michael Sep 21 '18 at 11:50
  • You can user either ACF or toolset for this requirement.By using both of this we will get the uploaded images in the media libraray – Adarsh Sep 21 '18 at 11:56
  • @Michael thank you for your suggestion. I do not want to use Plugin to do that. I will attentively look at the suggested article. – Mardy Sam An Sep 23 '18 at 3:04
  • @Adarsh thank you for your response. I understand that ACF is a nice plugin, but I prefer not to use plugin. I wonder what is the toolset you are refering to? – Mardy Sam An Sep 23 '18 at 3:05
  • @MardySamAn its also a plugin – Adarsh Sep 24 '18 at 7:08
0

There are several tasks you need to perform when you choose to do with custom code. And I personally think they're complicated tasks. Here is the list of what I can imagine.

  1. Hook to the category edit page to add a new form for upload image. This can be done with the hook {$taxonomy}_add_form_fields.
  2. Handle the image upload. Depend on what you want the upload field to be, it can be a HTML file input or a button to open the Media Library popup.
  3. If it's just a file input, then you have to work with pure PHP to handle upload via $_FILES.
  4. If it uses Media Library, then you need to work with JS to trigger the popup.

As you're developing a theme, it can take a lot of time working on that. Besides, it belongs to plugin territory.

So, I'd suggest using a plugin for that. Meta Box framework with MB Term Meta extension works great in this case.

Disclaimer: I'm the author of Meta Box.

  • I appreciate your precise answer. I will consider using the suggested plugin. – Mardy Sam An Sep 25 '18 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.