The [gallery] shortcode accepts the columns='0' as an attribute so that it doesn't insert any breaks in the HTML between gallery items, however this option is not available in Gallery Settings interface ("Add Media" pop-up when editing pages/posts).

I've located the code in wp-includes\media-template.php line 396 to 406;

<label class="setting">
    <span><?php _e('Columns'); ?></span>
    <select class="columns" name="columns"
        <?php for ( $i = 1; $i <= 9; $i++ ) : ?>
            <option value="<?php echo esc_attr( $i ); ?>" <?php selected( $i, 3 ); ?>>
                <?php echo esc_html( $i ); ?>
        <?php endfor; ?>

I don't want to directly edit a core file but I would like to add <option value="0">Responsive</option> to that list. What's the best way to do that without editing core files? I was thinking some kind of filter, although I'm not too familiar with them.

  • 3
    Might this be something that should be submitted as a bug/patch in Trac? – Chip Bennett Jan 23 '14 at 14:48
  • There is no "right" way to hack a Core file as an end user, but as @ChipBennett suggests, you could fix the problem and submit a patch. – s_ha_dum Jan 23 '14 at 14:58
  • So then is there a way to modify (even if it's not the "right" way) outside of the core files? – Michael Ruta Jan 23 '14 at 15:52
  • Please do not touch wordpress core files! This is very important thing. You need to find some filters for this stuff. – NetWeight Company Apr 10 '14 at 2:29

You're in a pretty good pickle here.

There are a couple things you can do as far as I can tell. Both of them are a little tricky.


The one I would recommend would be to make use of the do_action('print_media_templates') at the bottom of that file. It's not perfect, but you could add in an additional field here to take care of the responsive aspect you want to add.

Possible, but not recommended

Another option is to actually modify the actions that are being set in /wp-includes/media.php lines 2022-2024. Check this out:

function custom_print_media_templates() {
  remove_action( 'admin_footer', 'wp_print_media_templates' );
  remove_action( 'wp_footer', 'wp_print_media_templates' );
  remove_action( 'customize_controls_print_footer_scripts', 'wp_print_media_templates' );

  add_action( 'admin_footer', 'custom_print_media_templates' );
  add_action( 'wp_footer', 'custom_print_media_templates' );
  add_action( 'customize_controls_print_footer_scripts', 'custom_print_media_templates' );
add_action( 'wp_enqueue_media', 'custom_print_media_templates' );

You would then have to go create a function called custom_print_media_templates() that mirrors the one in wp-includes/media-template.php. The problem here is that any changes to WordPress core for this file would need to be replicated in your file. That's why I don't recommend this path.

| improve this answer | |
  • very good thinking – prosti Sep 14 '16 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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