You can use wp_enqueue_media() in your admin_enqueue_scripts hook.
In a javascript file hook it into a button and use insert event to capture the selected image’s details
$('.media-button').click(function() {
var media_uploader = wp.media({
frame: "post",
text : "Add image",
state: "insert",
multiple: false
});
media_uploader.on("insert", function(){
var json = media_uploader.state().get("selection").first().toJSON();
var image_name = json.filename;
var image_url = json.url;
var image_caption = json.caption;
var image_title = json.title;
});
});
Related Posts:
- Saving data-URI to media library
- Customizing the 3.5 “Add Media” popup (Backbone.js)
- Change Media Uploader default directory
- WordPress Media mime type filter problem 4.0
- How to send email in wordpress with more than one attachments
- What filter should I use to insert a button inside on Media>Add New
- How to replicate Media Library “Add New” on Plugin Settings Page
- Create a new post using rest api and save featured image using an external image url
- How to move an image in a plugin to the upload directory and make it as a media of wordpress?
- wp.media Uncaught TypeError: Cannot read properties of undefined (reading ‘state’)
- wp.media libary pdf type
- Is it possible to convert various image types from remote URLs to WebP and then serve them immediately?
- upload image to wordpress media library failed for custom post type
- How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
- How to Fix HTTP Error When Uploading Images?
- How to implement color picker from wordpress in my plugin?
- Add async script
- API to trigger prompt on leaving page
- Add tinymce buttons to caption textarea in media uploader
- Test to see if jQuery or Prototype is queued by another plugin?
- jQuery in header or footer
- How to get all files inserted (but not attached) to a post
- Password protect some uploaded files, so only logged-in users can view them
- Changing upload directory for plugin uploads only
- Upload file to remote storage
- How to extend LINK TO functionality in ATTACHMENT DISPLAY SETTINGS
- Trigger JS when featured image upload window is opened in admin
- How to Add a .js file Only in one specific Page Dynamically to Head
- wp_localize_script $handle
- How to prevent loading of all plugin’s resources?
- How to trap “Publish” button to check for meta box validation?
- Pass javascript result to shortcode executer function
- Mediaelement.js feature doesn’t work
- Use js script from one plugin in another plugin
- Making a custom widget that includes a tinymce and works in Site Origin Page Builder
- Looking for callback function after Gutenberg is rendered?
- What’s the better way to add an inline script?
- Proper way to hook wp_get_attachment_url
- Gutenberg: useDispatch is not a function – @wordpress/data included
- Make a list with header and subtext in Gutenberg blocks
- Prevent Javascript Facebook SDK Conflicts in plugin
- Uploading images from a custom page using blueimp uploader?
- how to include javascript file and css file in wordpress
- How to retrieve alt attribute for an attachment (uploaded image)?
- Why is my javascript not invoked in my hooks except wp_head?
- Is there an event or an other method that tells me the preview is loaded?
- Handling image uploads without thickbox
- get post attachment using ajax
- How to enable sorting in custom media uploader in plugin
- Uppload image from another source wp.media
- Do I have to worry about useState causing a re-render?
- Multiple media uploader buttons target only one input on the same page
- wp_set_object_terms not updating database without a die()
- Why is the temporary upload always 4.1K
- My WordPress plugin cannot load my JavaScript file
- javascript datatables in a plugin
- What is the way to add additional fields to attachments in 3.5+?
- How can I avoid conflicts between plugin and theme?
- How to control an elements classes from multiple Gutenberg sidebar controls?
- How should I go about registering JavaScript that isn’t a file? [duplicate]
- adding a button to the media uploader
- How does WordPress decides how many sizes of an image to create?
- Translate javascript with WordPress built-in localization API for static strings
- Hook after attachment added and cropped
- How to create a digital product download link that can’t be used twice?
- Insert Into Post Not Working For Audio File Using jQuery
- Developing the save function in Gutenberg blocks
- How to change the text of the “You are about to permanently delete these items…” alert message when deleting media from the media library?
- How to submit/upload data to database and in specific folder?
- Get audio metadata on file upload
- Insert attachments from custom uploader into post (regular uploader style)
- Getting incorrect filepath inside custom block front-end output using @wordpress/create-block tutorial
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- Multiple TinyMCE on button click is initialized and appended but why only last one is writeable?
- HTMLCollection not counting right in editor? / for loop not working on elements in DOM
- Trying to rename a file upload as the hash of file content on wordpress
- converting a node.js project into a wp plugin
- Is “document loaded” different on admin side than public side?
- why is apiFetch throwing Unhandled Promise Rejection: TypeError: Object is not a function
- Home page is not loading, where in other pages are displaying on the site
- Default media uploader is not showing in wordpress website
- Load script on frontend from widget plugin
- WordPress with React: Saving and Using Data Collected with fetch
- wp_delete_attachment doesn’t delete image files / doesn’t work
- Using JavaScript in WordPress page to call for server data using AJAX
- Unexpected issue when using attachment_fields_to_edit filter
- Uncaught ReferenceError: kpoejy is not defined
- How to destroy or dispose wordpress uploder/manager?
- Limit attachment caption characters
- controlling whether upload is attached to post or not
- Changing upload directory for plugin uploads only
- On one of my sites a file is shown as 404 but the file IS there
- How can i add insertion point between inner blocks in my custom block like core blocks
- How can create a custom plugin to call my webapi after any registration or membership plugin functionality
- Load images from CDN and custom features to “Add Media” dialogue
- Reinitiate Gutenburg’s blocks using javascript
- how to add contact form 7 shortcode in javascript variable
- Insert text programmatically in WordPress Gutenberg Editor
- WordPress Media Uploader not displaying image that has just been uploaded
- Can you open a media frame to sellect an attachment to associate with another attachment you are editing on an existing media frame?