With the new release of WordPress will come the ability to declare support for HTML5 markup in galleries. Once a theme declared support, the definition list elements will be replaced by <figure> and <figcaption> for better semantics.

If you decide to not only adopt this new feature but also maintain backwards compatibility, then there are two ways to achieve that:

Style not only the new HTML5 elements, but also add CSS selectors for the traditional definition list elements. This is the route we chose for _s to keep it as simple as possible. Filter the shortcode attributes and override the tag parameters. Since the shortcode_atts_gallery filter was introduced in 3.6, you’ll be backwards compatible with the latest two versions.

The callback to override the tag parameters could look something like this:

/** * Replaces definition list elements with their appropriate HTML5 counterparts. * * @param array $atts The output array of shortcode attributes. * @return array HTML5-ified gallery attributes. */ function prefix_gallery_atts( $atts ) { $atts['itemtag'] = 'figure'; $atts['icontag'] = 'div'; $atts['captiontag'] = 'figcaption'; return $atts; } add_filter( 'shortcode_atts_gallery', 'prefix_gallery_atts' );

This second way of adding backwards compatibility has the added benefit that it also adds forward compatibility, as you’re able to use HTML5 markup for galleries now, even before WordPress 3.9 will be released in April.

Please keep in mind that WordPress will no long output its default gallery styles by default, when HTML5 support for galleries has been added.

0.000000 0.000000

Share this: Twitter

Facebook

More

Email

LinkedIn



Pinterest

Pocket



Print

Reddit



Skype

Telegram



Tumblr

WhatsApp



Like this: Like Loading... Related