Search code examples
jquerywordpressmultiple-selectmedia-librarywordpress-media

Wordpress Media Library select multiple images on click


I have enqueued wp_enqueue_media(); on the frontend.

I have dded two kind of buttons, one for single selection and the second for multiple images selection

if($(this).hasClass('multiple-image-button')) {
            // Set the wp.media attributes
            var send_attachment_multiple = wp.media({
                title : 'Choose or Upload an Image',
                multiple: true,
                library: {
                    type: [ 'image' ]
                },
            });
        } else {
            //uploadSingleImages(this);
            // Set the wp.media attributes
            var send_attachment_multiple = wp.media({
                title : 'Choose or Upload an Image',
                multiple: false,
                library: {
                    type: [ 'image' ]
                },
            });
        }

Everything is working fine with this. Now the issue i think is the way how wordpress media library works with multiple image selection. when selecting multiple images it force the user to click shift/ctrl and image click to select all needed images (which is ok for desktop).

Now when i am on mobile i cant select multiple images even if multiple selection equals true.

This is how it works currently (usual wordpress behaviour also on the backend) enter image description here

This is how it should work for multiple image selection (on click without shift/ctrl/etc..) enter image description here

What is the best way to enable the bulk selection when trying to select multiple images? or there is any idea how to achieve this?


Solution

  • I couldn't imagine that the solution could be so easy. After spending many hours i could find the solution.. So if you want to select multiple images without using shift/ctrl/etc which means only on click, you need to replace

    multiple: true,
    

    with

    multiple: 'add',