WordPress.org

Make WordPress Core

Opened 12 months ago

Last modified 5 months ago

#21082 new defect (bug)

The Gallery shortcode relies on #gallery-instance to hook the CSS, but the id sometimes isn't specific enough

Reported by: matveb Owned by:
Priority: normal Milestone: Awaiting Review
Component: Gallery Version:
Severity: normal Keywords: has-patch needs-testing
Cc: lancewillett, mdhansen@…

Description

The Gallery CSS selector uses the id attribute, which is of the form #gallery-{instance}. On some scenarios (like infinite scroll) a follow up gallery on a another post can have the same #gallery-x selector, thus over-writing the previous gallery style.

Proposed solution: make the #id more unique by including the postid number. (Attached patch.)

(It could potentially impact some themes that used #gallery-1 to style galleries, but theme's shouldn't be using that in the first place, I believe.)

Furthermore, it may be good to change the whole style block to use classes instead of the id so that it's easier for themes to deal with CSS specificity—and helps them not fall back to the #id.

Attachments (2)

21082.diff (480 bytes) - added by matveb 12 months ago.
21082.2.diff (1.7 KB) - added by MikeHansenMe 5 months ago.

Download all attachments as: .zip

Change History (7)

matveb12 months ago

comment:1 lancewillett12 months ago

  • Cc lancewillett added

+1 to not styling with ID values, in the core CSS output.

MikeHansenMe5 months ago

comment:2 MikeHansenMe5 months ago

  • Cc mdhansen@… added
  • Keywords needs-testing added

This patch moves the general styles to use the class and also takes advantage of the $instance var to only add it once. This will likely still be added on the first gallery of each infinite scroll load. This is still much better than being added to every gallery.

comment:3 DrewAPicture5 months ago

I like where you're going with 21082.2 but if we're going to remove $selector from the general styles, I think I'd much rather have them printed via wp_head than in with the galleries.

comment:4 follow-up: MikeHansenMe5 months ago

Yea, I thought the same thing but I do not think you can add anything to wp_head from within a shortcode. I think it is to late. I can/will check into that.

comment:5 in reply to: ↑ 4 kovshenin5 months ago

Replying to MikeHansenMe: wp_head is indeed too late for shortcodes.

Note: See TracTickets for help on using tickets.