I know how to use the new media uploader in WP 3.5 and integrate it with plugins and themes but I have a problem, say the user selected the image and the frame closed I want when he open it again the image user selected before being selected in the gallery or highlighted.

the codex doesn't have any api doc about it

$button.on('click', function(e){
    // prevent default behavior
    if ( typeof file_frame != 'undefined' ) {

    // create and open new file frame
    file_frame = wp.media({
        //Title of media manager frame
        title: 'Select an Image',
        library: {
            type: 'image'
        button: {
            //Button text
            text: 'Use Image'
        //Do not allow multiple files, if you want multiple, set true
        multiple: false,

    //callback for selected image
    file_frame.on('select', function() {
        var selected = [];
        if ( is_multiple ) {
            // multiple images selected
            var selection = file_frame.state().get('selection');
            selection.map(function(file) {
        } else {
            // single image

        // loop through selected images
        for (var i in selected) {


    // open file frame

can anyone help

  • Take a look at those demos and then update your question with some code.
    – kaiser
    Jul 10, 2013 at 20:25
  • my code is the usual code for Media Uploader, what I need is the extra code for make an item in the media library selected by default when the media uploader opens
    – Nabeel
    Jul 10, 2013 at 22:05
  • Then please show us your "usual" code...
    – kaiser
    Jul 10, 2013 at 22:18
  • code added, I mint with "usual" that I didn't want to bore anyone, thanks for you time
    – Nabeel
    Jul 12, 2013 at 10:34
  • on file_frame.on('select', function () , use insert instead of select.
    – mghhgm
    Feb 15, 2019 at 23:00

1 Answer 1


I found the solution from here:


And it works. Here's my modification and this is using a single-image select media frame:

frame.on('open', function(){
    var selection = frame.state().get('selection');
    var selected = $('#image-id').val(); // the id of the image
    if (selected) {
  • this code select image in newly opened wp media uploader, but when I choose another image in uploader and click "Select" it does not update in product images metabox for woocommerce.
    – Toniq
    Oct 11, 2020 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.