Created
February 12, 2017 15:01
-
-
Save webhasan/e319cdd3d8ba1727a7ca8fe406dbd0d7 to your computer and use it in GitHub Desktop.
WordPress Media Upload
This file contains hidden or 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
<?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) ; | |
}); |
This file contains hidden or 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
;(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