Forked from blogjunkie/child-theme-settings.php
Last active
December 19, 2017 15:42
-
-
Save KustomDeveloper/8654fced415b6faf631ccc4b331989ad to your computer and use it in GitHub Desktop.
Integrate the WordPress Media Uploader in Theme Options. Reference this function from your add_meta_box() callback
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 | |
function upload_image_metabox() { | |
echo '<p><strong>Upload image</strong></p>'; | |
echo '<input type="text" id="child_logo_url" name="' . $this->get_field_name( 'welcome-image' ) . '" value="' . esc_attr( $this->get_field_value( 'welcome-image' ) ) . '" size="50" />'; | |
echo '<input id="child_upload_logo_button" type="button" class="button" value="Upload Image" /> '; | |
?> | |
<script type="text/javascript"> | |
// JavaScript to launch media uploader, should be enqueued in a separate file | |
jQuery(document).ready(function() { | |
jQuery('#child_upload_logo_button').click(function() { | |
wp.media.editor.send.attachment = function(props, attachment) { | |
jQuery('#child_logo_url').val(attachment.url); | |
} | |
wp.media.editor.open(this); | |
return false; | |
}); | |
}); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment