WordPress.org

Ready to get started?Download WordPress

Forums

Change the default settings of a gallery (4 posts)

  1. somtam
    Member
    Posted 1 year ago #

    Hello everybody,

    I'm trying to change the default settings of the WP gallery.
    I mean, the number of columns, and the link.
    I was looking for some filter, but I did't find them.

    I see, as an example, that the default number of column is declared in the media-template.php, like this:

    <option value="<?php echo esc_attr( $i ); ?>" <?php selected( $i, 3 ); ?>>

    so I think there's no way to change it ( of course I don't want to touch the core! ).

    I can go to filter the_content ( like show in zeo's blog ). But I don't like to add filter to the_content, because I think it uses a lot of resources on every page.

    So is there someone that know how to do that?

    thanks!

  2. Olly - OWMC
    Member
    Posted 1 year ago #

    it would be nice to see wordpress at least add the option of chosing "0" columns from the drop down menu. that way it won't break in fluid layouts.

  3. Olly - OWMC
    Member
    Posted 1 year ago #

    i've just used this to clear all the linebreaks from wordpress's fascist column structure:

    <script>
    	jQuery('.gallery br').remove();
    </script>

    found the idea to use jquery to edit wp core in a future-version proof way from reading this.

  4. bcworkz
    Member
    Posted 1 year ago #

    The selection in the media template merely sets the 'columns' attribute in the shortcode that gets generated. The shortcode by default is processed by gallery_shortcode() defined in wp-includes/media.php. You can cause the gallery shortcode to be processed by your own function by hooking the filter 'post-gallery'. Your function could choose to ignore the columns attribute and display the images any way you like. Naturally, your function can also generate whatever links you like as well.

    This is the "clean" way of taking over the gallery shortcode processing. If your function is based largely on the default code, you need to assume the responsibility of reviewing any updates to the default code and applying any pertinent modifications to your own function.

Topic Closed

This topic has been closed to new replies.

About this Topic