Make WordPress Core

Opened 14 years ago

Closed 4 years ago

#21082 closed defect (bug) (wontfix)

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

Reported by: matveb Owned by: obenland
Priority: normal Milestone:
Component: Gallery Version:
Severity: normal Keywords: needs-testing has-patch
Cc: Focuses:

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 (3)

21082.diff (480 bytes ) - added by matveb 14 years ago.
21082.2.diff (1.7 KB ) - added by MikeHansenMe 14 years ago.
21082.3.diff (1.2 KB ) - added by antpb 11 years ago.

Download all attachments as: .zip

Change History (15)

@matveb
14 years ago

#1 @lancewillett
14 years ago

  • Cc lancewillett added

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

#2 @MikeHansenMe
14 years 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.

#3 @DrewAPicture
14 years 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.

#4 follow-up: @MikeHansenMe
14 years 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.

#5 in reply to: ↑ 4 @kovshenin
14 years ago

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

#6 @ethitter
13 years ago

  • Cc erick@… added

#7 @MikeHansenMe
12 years ago

  • Keywords needs-refresh added; has-patch removed

#8 @antpb
11 years ago

  • Keywords has-patch added; needs-refresh removed

Refreshed the patch below...

@antpb
11 years ago

#9 @obenland
11 years ago

  • Milestone Awaiting Review4.5
  • Owner set to obenland
  • Status newaccepted

21082.diff has been running on WP.com without issues for 3.5 years now.

The other patches still need a good amount of testing. I think we should search the theme repo to see if themes do use the id selector and try to bring this in early in the cycle to give it time to soak.

#10 @obenland
11 years ago

53 themes in the repo use a #gallery-1 selector in one way or another.

#11 @obenland
11 years ago

  • Milestone 4.5Future Release

#12 @desrosj
4 years ago

  • Resolutionwontfix
  • Status acceptedclosed

I'm going to close this out as a wontfix.

A search of the theme directory today returns 271 occurrences of #gallery-1 in 112 themes. Unfortunately I think this is just something we'll need to live with to maintain backwards compatibility in themes.

Additionally, with the introduction of the block editor and full site editing, shortcodes (though still supported) are no longer the recommended way to display a gallery.

This has been solved in the gallery block. IDs are no longer used, and a .wp-block-gallery class is applied to the <figure> tag wrapping the gallery images.

Note: See TracTickets for help on using tickets.