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
- Multimedia upload error in my wordpress job board plugin
- Plugin writing: access file that was just uploaded
- Is there an event or an other method that tells me the preview is loaded?
- Custom delete option button in plugin settings
- WordPress Plugin with a shortcode that dynamically generates javascript. Can I use add_action without wrapping the javascript in a function?
- Switch between tabs on “Insert Media” dialog
- Use the WP media uploader dialog for uploading a form attachment (non-admin). Offering progress and drag and drop feedback
- Handling image uploads without thickbox
- get post attachment using ajax
- How to enable sorting in custom media uploader in plugin
- How to prevent UNDO on guternberg block editor
- Uppload image from another source wp.media
- Do I have to worry about useState causing a re-render?
- Creating a custom Gutenberg block with columns
- “import declarations may only appear at top level of a module” when importing WooCommerce API node module
- how to get link of added document with a post
- 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
- Gutenberg: import dependency or assign from global variable?
- Capture mediaelement events
- Why is the temporary upload always 4.1K
- My WordPress plugin cannot load my JavaScript file
- javascript datatables in a plugin
- Prevent Delete Attachment by URL or When Submit
- Get attachments from a post
- wp.media javascript issue with on select
- PowerPress mobile media player
- add javascript files only when plugin is called?
- What is the way to add additional fields to attachments in 3.5+?
- Upload multiple images and insert them into custom html code
- 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
- How can I avoid conflicts between plugin and theme?
- How to control an elements classes from multiple Gutenberg sidebar controls?
- Redirect to another page using contact form 7? [closed]
- How should I go about registering JavaScript that isn’t a file? [duplicate]
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- wp_editor add media button not working
- should i be checking for jquery before enqueing it in a plugin
- WordPress Specified file failed upload test
- Loading custom js file on the admin page through plugin
- Run a function when new image is uploaded in media library
- Run JavaScript validation script on form submit in plugin
- Custom Plugin – CSS works, JS doesn’t
- Uploaded attachment not set as featured image
- Get images attached to a specific page
- 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?
- Need help about understand api, wp, $ syntax in WordPress plugin script
- How to add a panel/box/widget/are/screen to the right side of edit post/page confusion
- Insert Into Post Not Working For Audio File Using jQuery
- Service Worker Uncaught (in promise) DOMException
- Developing the save function in Gutenberg blocks
- How to disable drag-and-drop upload function in Media Library?
- Gutenberg – is it ok to load dependencies multiple times?
- How to change the text of the “You are about to permanently delete these items…” alert message when deleting media from the media library?
- Preventing double loading JS scripts (like React) when developing for Gutenberg
- How to submit/upload data to database and in specific folder?
- About a programming language starts with [closed]
- Cleaning a filename after image sideloading a url that contains `%20`
- Get audio metadata on file upload
- Referencing files in JavaScript in WordPress Plugin
- How to insert HTML/CSS/JS into my iframe plugin?
- Is there a WordPress plugin to design WebGL? [closed]
- Should I put my plugin javascript inline?
- Insert attachments from custom uploader into post (regular uploader style)
- Why doesn’t update_post_meta work for certain strings?
- How to write a shopping queue line plugin with a queue button?
- Hook on file upload
- Problem with inserting multiple images in gallery of each WooCommerce product programmatically
- wp.media gallery collection sometimes undefined
- Query String Filtering API
- Getting incorrect filepath inside custom block front-end output using @wordpress/create-block tutorial
- Insert and read media from the WordPress library and call in the plugin
- Do custom post type (CPT) attachments/media store the parent post ID?
- 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?
- 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
- converting a node.js project into a wp plugin
- What happens/fires when you select a block in the editor?
- Is “document loaded” different on admin side than public side?