2

Is there a way to set default number of columns in gallery? It is set to 3, and currently I change it manually for every gallery in post I create to 4.

Here are the settings on the right https://codex.wordpress.org/images/c/c7/edit-gallery-drag.png

In codex they say "3 Columns is the default settings, which is ideal for most sites.", but not a word about how to change it. I have only found that I can add it to the shortcode ( [gallery columns="4"] ), but this isn't what I need

3

You can override many of the Gallery Settings using the media_view_settings filter:

/**
/* Gallery Default Settings
/* @param Array $settings
/* @return Array $settings
*/
function theme_gallery_defaults( $settings ) {
    $settings['galleryDefaults']['columns'] = 5;
    return $settings;
}
add_filter( 'media_view_settings', 'theme_gallery_defaults' );

To change more settings, the easiest way is to use Developer Tools to inspect the actual field. What you're looking for is an attribute called data-setting. Grab that value and use it to override the defaults.

Of course it should be noted that this will not update galleries that already exist. You'll have to run a filter on the_content to change it on the fly.

Credits: https://wordpress.stackexchange.com/a/169491/7355

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.