• I’d like to have 2 columns and link to file media as defaut settings, I have underscores as theme, I have tryed a code that is not working:

    function theme_gallery_defaults( $settings ) {
        $settings['galleryDefaults']['columns'] = 2;
        $settings['galleryDefaults']['link'] = 'file';
        return $settings;
    }
    add_filter( 'media_view_settings', 'theme_gallery_defaults' );

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • If you are using wp-block “gallery” you can change it through settings. There a option “column” in which you can set no of columns you want. Below there is option to set link.

    Thread Starter sacconi

    (@sacconi)

    I cant do it manually for hundres of posts, I need to code the default settings

    Moderator bcworkz

    (@bcworkz)

    There are no “galleryDefaults” items in media settings by default. Were they added by a plugin or your theme? You could examine what settings are available by var_dumping $settings from your filter callback. The edit page display will get corrupted, but you can view the output by viewing the page’s source HTML. TBH I don’t know where the gallery defaults are stored. They might be hardcoded for all I know.

    In any case, for existing galleries the column count and linkTo settings are saved as part of post content. You cannot alter these by changing the defaults. If you have hundreds of existing galleries that you want to change, it might be worth developing a custom script that goes through all of the posts looking for galleries and updating the related settings when found. In the case of linkTo, if that needs to change, all the related anchor link href attributes in the gallery HTML would need to be updated. This custom script could become complex to implement.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘gallery default settings’ is closed to new replies.