How to insert Gallery shortcode to a meta box

When we create a Image Gallery from the Media Modal Box and click on “Insert Gallery” button, the gallery shortcode is added to the main text area.

Is there a way to detect which Post Format is selected, and if its “Gallery” then is there a way to modify the action of the “Insert Gallery” button to add the shortcode to a meta box instead of the text area.

1 Answer
1

That is a weird way to do it, shortcodes are really meant for inserting into the editor, if you want to program some functionality it’s better to go straight into the template/code itself.

//check if post format is gallery type
if ( has_post_format( 'gallery' ) {
    echo do_shortcode('');
}

Leave a Comment