Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#18472 closed enhancement (duplicate)

The gallery shortcode might need some extra filters.

Reported by: kovshenin's profile kovshenin Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Gallery Keywords:
Focuses: Cc:


Sorry if this is a duplicated, tried searching didn't find much. Basically it's about the gallery shortcode markup. The gallery shortcode itself allows you to specify the itemtag, icontag and the captiontag which I don't think is the best approach if the end-user decides to switch to a new theme at some point, we wouldn't want to get them to rewrite all their shortcodes in all their posts, right?

Anyhow, I'm not asking to remove the mentioned shortcode attributes, but rather to filter the defaults. The dd/dt combination might not be the best markup in the world and simply changing that to divs and spans or ul/li might be a good choice for some theme developers.

I would love to create a gallery_shortcode_markup filter that would run through an array of itemtag, icontag and captiontag, that way theme (and plugin) developers won't be able to override the order, size, columns, and others which would end up making it a little weird and fuzzy in the insert gallery UI. Talking about media.php, the gallery_shortcode function, I can create a patch if you think it would be useful.

Thanks, and sorry again if this is a duplicate!

Change History (4)

#2 @coffee2code
13 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Check out #15155 (which I think is more appropriate here than #14130). It looks to me like the shortcode attributes filter I proposed there should fulfill your request. With it you can override the values that had been specified for the instances of the shortcode (whether it originated from the shortcode attribute defaults or values supplied by the user). Here's a simple example using the filter. I'm closing this as a duplicate, but feel free to reopen if you feel the solution is inadequate for what you wanted.

add_filter( 'shortcode_atts_gallery', 'gallery_shortcode_change_markup', 10, 3 );

 * Change markup for gallery shortcode attributes of itemtag, icontag, and
 * captiontag regardless of default values or what user provided
 * @param array $result The shortcode_atts() merging of $defaults and $atts
 * @param array $defaults The default attributes defined for the shortcode
 * @param array $atts The attributes supplied by the user within the shortcode
 * @return array The potentially modified $result array
function gallery_shortcode_change_markup( $result, $defaults, $atts ) {
	$result['itemtag']    = 'div';
	$result['icontag']    = 'span';
	$result['captiontag'] = 'em';
	return $result;

#3 @kovshenin
13 years ago

Oh this sounds brilliant, never would have guessed how to search for that one since I was focused on the gallery and not as general and flexible as #15155. Simple and nice, thanks!

#4 @SergeyBiryukov
13 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.