By enququing an JS file we can do like this:
<img src="#" id="img-src">
<a href="#" id="img-upload">Add Image</a>
Content of JS file
jQuery(document).ready(function(e){
e.preventDefault();
jQeury('#img-upload').click(function(){
var upload = wp.media({
title:'Choose Image', //Title for Media Box
multiple:false //For limiting multiple image
})
.on('select', function(){
var select = upload.state().get('selection');
var attach = select.first().toJSON();
console.log(attach.id); //the attachment id of image
console.log(attach.url); //url of image
jQuery('img#img-upload').attr('src',attach.url);
})
.open();
});
});
Like this we can have it.
Related Posts:
- Enhance Media Manager for Gallery
- Custom collection in media manager?
- Checking if a file is already in the Media Library
- Adding more options to the instance of an image. (Attachment Display Settings)
- Change Media Uploader default directory
- How to extend LINK TO functionality in ATTACHMENT DISPLAY SETTINGS
- How can I view all WP generated thumbnails in Media Manager?
- Modify how gallery.js builds the shortcode [gallery ...] in tinyMCE?
- Bridge WordPress Media API with custom tinyMCE plugin [closed]
- How to get an image transferred via FTP or script to appear in Media Manager?
- Add Additional File Info (jpeg compression & file size) settings to Edit Images Screen
- Is it possible to modify the media library admin screen?
- Using the component outside the editor. select(‘core’) is null
- How to replicate Media Library “Add New” on Plugin Settings Page
- How to enable sorting in custom media uploader in plugin
- Upload multiple images and insert them into custom html code
- wp_editor add media button not working
- Run a function when new image is uploaded in media library
- How to create wordpress media library UI on plugin page
- wp.media gallery collection sometimes undefined
- Can’t load a script in my plugin page
- function add custom fields to media gallery
- WordPress Dropdown image select
- Changed media upload path for plugin, but generates error & shows wrong url
- How to destroy or dispose wordpress uploder/manager?
- Creating custom Insert Media page
- Thumbnails for media Library images
- Remove image in post when it’s removed in media library
- How do you filter get_media_items by mime type in a custom media upload tab?
- Upload to a specific media folder created by FileBird Lite
- Load images from CDN and custom features to “Add Media” dialogue
- upload image to wordpress media library failed for custom post type
- Add self-closing shortcode button to TinyMCE in WP 4.6
- WordPress Hook for user register
- How to make dynamically-generated content searchable in WordPress?
- Nav Menu meta failing to import
- How do I conditionally enqueue script for CPT single post type with plugin?
- Is it possible to remove next-post / previous-post with out creating a custom template?
- wp_localize_script $handle
- Escaping built-in WP function return strings
- Custom Rewriting to Plugin with Parameters
- Help adding image upload functionality to widget
- Script won’t load via plugin class
- How to override a function call in functions.php?
- Execute plugin for specific user role(s) only
- How can I render shortcode so that its not cached by Caching plugins?
- Does WordPress support WebP images?
- Sidebar widget to show popular post not working?
- WP_Query returns no results
- Enqueue scripts in footer
- Is It Always a Best Practice to Decouple the Frontend from the Admin Area When Developing a WordPress Application?
- the_editor() function
- Including the necessary functions for a custom ajax registration form
- Why doesn’t my simple the_title filter get applied?
- WordPress clean internationalization for menus?
- Dashboard – get status and position of metaboxes and pass them to ajax method
- Is it possible to install a theme via a plugin?
- JSX in WordPress Plugin Development
- W3 Total Cache JS and css Minify folder are empty
- Form doesnt save to database
- Including comments meta box on a plugin page
- How to create custom settings page for custom plugin
- Why wp_die() doesn’t work with wp_redirect but exit() works
- Internationalizing Plugin
- Update File Once Every 30 Days
- Taxonomies within plugin invalid
- Make Database query only when option is updated
- Looking for a better way to initiate cron job
- shortcode executed in the page editor
- Plugin header: WP and PHP version control uses wp_die(), can I change that?
- Form using admin-post.php gives 404 after submission
- per blog metadata for plugin
- Completely isolate a plugin view so it doesn’t load the theme
- Custom Post Type Object – Undefined Variables
- How to translate wordpress backend to another language
- How does “Your comment is awaiting moderation” work?
- How to link to custom “archive like” page with custom permalink rules “dynamically”
- rewrite_rules problem
- Dynamic page generation upon purchase of a product
- Custom post type change permalink query
- Settings API not saving
- Allowing duplicating users with same user_login and user_email
- Why does theme’s reset CSS have higher precedence of plugin’s CSS?
- Updating the_post content is only working with Twenty Twenty theme
- Redirect WooCommerce checkout to cart
- Scripts/styles not loading on cloned WP Site when logged in
- Initializing rest endpoint issue
- WordPress plugin how to run function when button is clicked
- Save in my custom admin page and redirect to the saved object
- How to display archive by selecting year and then selecting month
- Undefined notice on unset field
- Theming Custom Plugin Page
- Script work on non logged in user but not work for logged in user?
- admin page passing $_POST variables to itself
- Can wp_schedule_single_event be used to run background proccess?
- Get user logged in status from within a plugin. $current_user not defined
- How to change url’s in WordPress when changing domain [duplicate]
- Email verification feature in wordpress social login plugin
- Is wordpress plugin development active? [closed]
- Saving metabox updates causing fatal error