Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#23787 closed defect (bug) (fixed)

Gallery displayed even when the gallery shortcode is inside an HTML comment

Reported by: mark-k Owned by: SergeyBiryukov
Milestone: 3.6 Priority: normal
Severity: normal Version: 3.4
Component: Gallery Keywords: has-patch
Focuses: Cc:


The gallery shortcode emits HTML comment which cause HTML to break when the shortcode is inside a comment as HTML doesn't support nested comments

Adding the following in the text editor

<!-- [gallery ids="423,424,202,155,148,150"] -->

generates the following HTML

		<style type='text/css'>
			#gallery-1 {
				margin: auto;
			#gallery-1 .gallery-item {
				float: right;
				margin-top: 10px;
				text-align: center;
				width: 33%;
			#gallery-1 img {
				border: 2px solid #cfcfcf;
			#gallery-1 .gallery-caption {
				margin-left: 0;
		<!-- see gallery_shortcode() in wp-includes/media.php -->

related #23786

Attachments (2)

gallery.patch (619 bytes) - added by mark-k 5 years ago.
23787.diff (818 bytes) - added by aaroncampbell 5 years ago.

Download all attachments as: .zip

Change History (9)

#1 @SergeyBiryukov
5 years ago

  • Milestone changed from Awaiting Review to 3.6

I guess we could remove the HTML comment from gallery_shortcode() (as you suggested in #23786), it doesn't seem necessary.

#2 @toscho
5 years ago

  • Cc info@… added

#3 @mark-k
5 years ago

Lets see if I got patch creation right...

5 years ago

#4 @mark-k
5 years ago

  • Keywords has-patch added

#5 @aaroncampbell
5 years ago

It seems like putting a gallery shortcode inside an html comment in a little edge-case, gallery.patch looks like a simple fix and I don't think the comment offers enough of a benefit to justify keeping it.

5 years ago

#6 @aaroncampbell
5 years ago

Nacin had a good idea, so 23787.diff moves the comment to a CSS comment instead of removing it.

#7 @SergeyBiryukov
5 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 24329:

Switch to a CSS comment in gallery_shortcode() to avoid breaking markup when the shortcode is used inside an HTML comment. props mark-k, aaroncampbell. fixes #23787.

Note: See TracTickets for help on using tickets.