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 I add an image upload field directly to a custom write panel?
- How to Fix HTTP Error When Uploading Images?
- How to provide translations for a WordPress TinyMCE plugin?
- How-to implement admin Ajax inside an admin WP_List_Table?
- API to trigger prompt on leaving page
- Add tinymce buttons to caption textarea in media uploader
- Include third party Javascript library which is not included in WordPress
- Refresh wp.media after ajax call
- Password protect some uploaded files, so only logged-in users can view them
- How to extend LINK TO functionality in ATTACHMENT DISPLAY SETTINGS
- How to Add a .js file Only in one specific Page Dynamically to Head
- How to find attachment ID for first image in a post
- How do i upload an image and return the image id?
- 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
- The changes I make to an external JS file of my WP plugin are only applied after I clear my browser’s cache
- `wp_set_script_translations` with `wp.i18n` does not return translated strings in simple plugin
- Use js script from one plugin in another plugin
- Looking for callback function after Gutenberg is rendered?
- Proper way to hook wp_get_attachment_url
- Prevent Javascript Facebook SDK Conflicts in plugin
- Sharing a common set of image files for media library, across all sites within multisite
- Uploading images from a custom page using blueimp uploader?
- Print WordPress username id inside JavaScript
- How to retrieve alt attribute for an attachment (uploaded image)?
- Mixing Regular Javascript With jQuery in a Plugin
- How to run a external JavaScript file on wp-admin if admin, and other if normal user?
- Where to call wp_enqueue_script in a plugin with custom template?
- Is there an event or an other method that tells me the preview is loaded?
- get post attachment using ajax
- How to enable sorting in custom media uploader in plugin
- How to prevent UNDO on guternberg block editor
- 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()
- wp.template() returns tags in Ajax response
- Why is the temporary upload always 4.1K
- My WordPress plugin cannot load my JavaScript file
- What is the way to add additional fields to attachments in 3.5+?
- Inserting code to HTML view from a pop up initiated from visual view
- Plugin – Make sure jquery is loaded in my settings page plus my JS file
- Redirect to another page using contact form 7? [closed]
- wp_editor add media button not working
- Run a function when new image is uploaded in media library
- How to create a digital product download link that can’t be used twice?
- Need help about understand api, wp, $ syntax in WordPress plugin script
- Developing the save function in Gutenberg blocks
- How to disable drag-and-drop upload function in Media Library?
- How to insert HTML/CSS/JS into my iframe plugin?
- Is there a WordPress plugin to design WebGL? [closed]
- Why doesn’t update_post_meta work for certain strings?
- How to write a shopping queue line plugin with a queue button?
- wp.media gallery collection sometimes undefined
- Getting incorrect filepath inside custom block front-end output using @wordpress/create-block tutorial
- Do custom post type (CPT) attachments/media store the parent post ID?
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- Rerender core Templates with with ToggleControl but it doesnt recognize block type
- 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
- How to use setAttributes outside of the edit function return
- Home page is not loading, where in other pages are displaying on the site
- Dynamically modify content added to table via javascript
- Default media uploader is not showing in wordpress website
- WordPress with React: Saving and Using Data Collected with fetch
- Javascript scroll eventHandler only working when I’m logged in in WordPress
- wp_delete_attachment doesn’t delete image files / doesn’t work
- Pass javascript result to shortcode executer function
- Add a Script button in W3 Total Cache plugin not working due to conflicting jQuery version
- Add language localisation to javascript alert?
- Uncaught ReferenceError: kpoejy is not defined
- Remove from a div by class name from post page if post author role is not administrator
- Attach an image to new posts
- Changing upload directory for plugin uploads only
- Thumbnails for media Library images
- On one of my sites a file is shown as 404 but the file IS there
- How do I use (or mimic) document.getElementById() on a page loaded from WordPress database?
- upload script in plugin development [duplicate]
- How can i add insertion point between inner blocks in my custom block like core blocks
- How do I access the contents of WordPress Classic editor in admin area with JavaScript?
- How to get the value entered in the input field in wordpres
- Leveraging Core Functionality in Icon Upload Plugin [closed]
- Upload to a specific media folder created by FileBird Lite
- 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
- Insert meta-description into Yoast-SEO input-field via JavaScript
- Reinitiate Gutenburg’s blocks using javascript