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('[gallery]');
  • I am actually trying to make this work for WordPress 3.6. Currently we need to first create a gallery which is then added to the Editor from where we have to copy paste it in the Gallery Meta Box. So I was trying to find a directly way to simply add some event to the "Insert gallery" button which could add the Gallery short code in the custom meta box. Mar 1, 2013 at 20:08
  • The direct and better way is to do at at the template level, thus my answer.
    – Wyck
    Mar 1, 2013 at 22:05
  • We are still working on the post formats UI for 3.6, which as I keep reminding you, is in active development. There is no chance it will remain a bare field for the final release. If you'd like to donate your time to making this work in core, it would be greatly appreciated. Mar 2, 2013 at 1:55
  • @helen, yes am aware of it, I just asked the question as I wanted to implement it in my current theme irrespective of whether it would be implemented in final WP 3.6. I have been able to create something basic but still lot of bugs. Once done will share it on WP trac Mar 7, 2013 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.