Insert wp gallery shortcode into custom textarea
Is there a way to insert wp gallery shortcode into custom metabox textarea ? I would like to have something like this:
New metabox in post/page with textarea and below textarea there are a button to open wp browse media gallery lightbox. then when we have done to select few images as gallery, click the "insert gallery" button will insert the shortcode to the textarea custom field.
is it possible ?
Thanks
====== Update: ======
I was able to show media library, now I don't have idea how to insert shortcode to the custom textarea when click button "insert gallery"
Here my code so far:
HTML
div class="uploader"
textarea name="settings[_cs_shortcode_gallery]" id="_cs_shortcode_gallery"/textarea
input class="button tf-browse-btn" name="_cs_shortcode_gallery_button" id="_cs_shortcode_gallery_button" value="Browse Gallery"/
/div
JS
var _custom_media = true,
_orig_send_attachment = wp.media.editor.send.attachment;
$('.tf-browse-btn').live('click', function(e) {
var send_attachment_bkp = wp.media.editor.send.attachment;
var button = $(this);
var id = button.attr('id').replace('_button', '');
_custom_media = true;
wp.media.editor.send.attachment = function(props, attachment){
if ( _custom_media ) {
$("#"+id).val(attachment.url);
} else {
return _orig_send_attachment.apply( this, [props, attachment] );
};
}
wp.media.editor.open(button);
return false;
});
$('.add_media').on('click', function(){
_custom_media = false;
});
What I want to achieve now are:
- How to set Create Gallery Tab as default tab when open the modal
- Insert gallery shortcode to the custom textarea
Please see the screenshot below for details
Topic media-library shortcode gallery custom-field Wordpress
Category Web