Skip to content

Instantly share code, notes, and snippets.

@webhasan
Created February 12, 2017 15:01
Show Gist options
  • Save webhasan/e319cdd3d8ba1727a7ca8fe406dbd0d7 to your computer and use it in GitHub Desktop.
Save webhasan/e319cdd3d8ba1727a7ca8fe406dbd0d7 to your computer and use it in GitHub Desktop.
WordPress Media Upload
<?php
/**
* Require File To Media Upload
*/
add_action("admin_enqueue_scripts", function() {
wp_enqueue_media();
wp_enqueue_script('feature-upload-script', get_template_directory_uri().'/upload.js', array( 'jquery' ), true, true) ;
});
;(function($) {
$('#upload_logo').on('click', function(e) {
e.preventDefault();
var that = wp.media({
title: 'Upload Logo',
button: {
text: 'Insert Logo'
},
multiple: false
}).open().on('select', function() {
var attachment = that.state().get('selection').first().toJSON();
//$('.image-container').html('<img src="'+ attachment.url +'" style="max-width: 100%;">');
//$('#hs_logo').val(attachment.url);
})
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment