-
-
Save ffoodd/6740308 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @note : Caption content is filtered to use html5 semantic elements figure & figcaption. First found on Zhen Huang's "Reverie". | |
* @author : @milohuang | |
* @see : http://themefortress.com/reverie/ | |
* @see : https://github.com/milohuang/reverie/blob/master/lib/clean.php | |
* @note : Then we add microdata. Found on Joost Kiens' Gists. | |
* @author : @joostkiens | |
* @see : https://gist.github.com/JoostKiens/4477366 | |
* @note : And in the end I add all ARIA role and attributes we need (group, aria-labelledby, aria-describedby). Group role is due to a lack of support of figure semantic. | |
* @see : http://www.kloh.ch/craw2013-html5-aria-et-accessibilite-web-479 | |
* | |
* @param string $val Empty | |
* @param array $attr Shortcode attributes | |
* @param string $content Shortcode content | |
* @return string Shortcode output | |
*/ | |
function ffeeeedd__caption( $output, $attr, $content ) { | |
if ( is_feed() ) { | |
return $output; | |
} | |
$defaults = array( | |
'id' => '', | |
'align' => 'alignnone', | |
'width' => '', | |
'caption' => '' | |
); | |
$attr = shortcode_atts( $defaults, $attr ); | |
if ( 1 > (int) $attr['width'] || empty( $attr['caption'] ) ) { | |
return $content; | |
} | |
$content = str_replace( '<img', '<img id="' . $attr['id'] . '" itemprop="contentURL" aria-labelledby="wp-caption_' . $attr['id'] . '"', $content ); | |
$attributes = ' class="wp-caption ' . esc_attr( $attr['align'] ) . '"'; | |
$output = '<figure' . $attributes .' role="group" itemscope itemtype="http://schema.org/ImageObject">'; | |
$output .= do_shortcode( $content ); | |
$output .= '<figcaption class="wp-caption-text pt1 " id="wp-caption_' . $attr['id'] . '" aria-describedby="' . $attr['id'] . '" itemprop="description">' . $attr['caption'] . '</figcaption>'; | |
$output .= '</figure>'; | |
return $output; | |
} | |
add_filter( 'img_caption_shortcode', 'ffeeeedd__caption', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment