Last active
March 22, 2018 22:38
-
-
Save jahid75/9467d3846838e707ebe3b6bd81947552 to your computer and use it in GitHub Desktop.
This script will help you to open media modal in wordpress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Very Simple Wordpress Image Uploader | |
jQuery(document).ready(function($) { | |
var frame; | |
$('#buttonID').on('click', function(event) { | |
event.preventDefault(); | |
// Create a new media frame | |
frame = wp.media({ | |
title: 'Select or Upload file Of Your Chosen Persuasion', | |
button: { | |
text: 'Use this file' | |
}, | |
multiple: false | |
}); | |
frame.on( 'select', function() { | |
var attachment = frame.state().get('selection').first().toJSON(); | |
$('#element_id_or_class').val(attachment.url); //Set attachement URL to the input | |
}); | |
frame.open(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment