Answer the question
In order to leave comments, you need to log in
How to make wp image upload field in admin panel on plugin settings page?
I am writing a plugin for wp and I have such a problem, it is necessary to make a field for uploading an image, or selecting it from the list of a media file, and as a result a link to this image should come. I have been looking for something similar for a long time, but most of the examples are only suitable for wp themes, but I need it to work from the admin page in the plugin settings. Thanks in advance for any help.
Answer the question
In order to leave comments, you need to log in
$('#add-image').click(function(e) {
e.preventDefault();
var image = wp.media({
title: 'Upload Image',
multiple: false
}).open()
.on('select', function(e){
var uploaded_image = image.state().get('selection').first();
console.log(uploaded_image);
var image_url = uploaded_image.toJSON().url;
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question