Make WordPress Core

Opened 7 years ago

Closed 6 years ago

#9400 closed defect (bug) (duplicate)

Gallery column number inline CSS issue

Reported by: ECodeStudio Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.7
Component: Gallery Keywords: has-patch commit
Focuses: Cc:


Having more than one gallery on a single page causes the latest one in code to override the "number of columns" property of the above ones.
This issues is easily fixed by adding the gallery id attribute.

Here is a code snippet to go into wp-includes/media.php

$output = apply_filters('gallery_style', "
        <style type='text/css'>
            #gallery-{$id} .gallery {
                margin: auto;
            #gallery-{$id} .gallery-item {

                float: left;
                margin-top: 10px;
                text-align: center;
                width: {$itemwidth}%;            }
            #gallery-{$id} .gallery-icon img {
                border: 1px solid #cfcfcf;
            #gallery-{$id} .gallery-caption {
                margin-left: 0;
        <!-- see gallery_shortcode() in wp-includes/media.php -->
        <div class='gallery' id='gallery-{$id}'>");

Attachments (2)

9400-quick.patch (471 bytes) - added by hakre 7 years ago.
9400.diff (883 bytes) - added by Denis-de-Bernardy 6 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 @hakre7 years ago

ECodeStudio, do you know how you can create a patch file? I do one, so you can take a look.

@hakre7 years ago

comment:2 @hakre7 years ago

Having an ID in there is nice to CSS but I do not understand your report fully.

comment:3 @Denis-de-Bernardy6 years ago

  • Keywords needs-patch added; gallery column number inline css removed
  • Milestone changed from Unassigned to 2.8

patch isn't good. it also needs to modify the css.

@hakre: there is a dup or two of this bug somewhere. But basically, what happens is:

  • create 3 posts, the first and last with galleries that have 3 columns, and the one in the middle with 2 columns.
  • display the blog page

notice that they all have the same number of columns. the suggested change fixes this quite well. much better than what was suggested in the related tickets.

comment:4 @ryan6 years ago

  • Component changed from Media to Gallery

comment:5 @hakre6 years ago

  • Keywords reporter-feedback added

Denis-de-Bernardy: So what to suggest. Just close this ticket? (would be fine with that).

@Denis-de-Bernardy6 years ago

comment:6 @Denis-de-Bernardy6 years ago

  • Keywords has-patch commit added; needs-patch reporter-feedback removed

comment:7 @Denis-de-Bernardy6 years ago

see also #7678 more essentially the same fix, using a class instead

comment:8 @hakre6 years ago

I suggest to close #9400 (this) as a duplicate because the suggestion in #7678 (there) are better.

comment:9 @Denis-de-Bernardy6 years ago

I'd agree if the patch on #7678 didn't contain a bug. $id != $post->ID in there. on the contrary, $id is that of an attachment.

Once that patch gets updated, +1.

comment:10 @Denis-de-Bernardy6 years ago

(or this one)

comment:11 @Denis-de-Bernardy6 years ago

  • Milestone 2.8 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

See #7678, with a better patch.

Note: See TracTickets for help on using tickets.