Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery( document ).ready( function(){
- jQuery( '#thumbnail_mediathek' ).click( function( event ){
- event.preventDefault();
- if ( frame ) {
- frame.open();
- return;
- }
- // Create a new media frame
- var frame = wp.media({
- title: 'Wähle ein Kategorienbild',
- button: {
- text: 'Verwende dieses Bild'
- },
- multiple: false // Set to true to allow multiple files to be selected
- });
- // When an image is selected in the media frame...
- frame.on( 'select', function() {
- // Get media attachment details from the frame state
- var attachment = frame.state().get('selection').first().toJSON();
- console.log( attachment );
- var txt = '<img src="' + attachment.url + '" style="max-width:100%" /><input type="hidden" name="_thumbnail_id" value="' + attachment.id + '" />';
- jQuery( '#thumbnail' ).find( 'img' ).remove();
- jQuery( txt ).insertBefore( jQuery( '#thumbnail button' ) );
- });
- // Finally, open the modal on click
- frame.open();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment