Last active
August 29, 2015 14:23
-
-
Save georgiecel/6ab43b153427a914cd25 to your computer and use it in GitHub Desktop.
semantic figure and figcaption elements for captioned images in WordPress – insert into functions.php
This file contains 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
function caption_shortcode($val, $attr, $content = null) { | |
extract(shortcode_atts(array('id'=> '','align'=> 'aligncenter','width'=> '','caption' => ''), $attr)); | |
if ( 1 > (int) $width || empty($caption) )return $val; | |
$capid = ''; | |
if ( $id ) { | |
$id = esc_attr($id); | |
$capid = 'id="figcaption_'. $id . '" '; | |
$id = 'id="' . $id . '" aria-labelledby="figcaption_' . $id . '" '; | |
} | |
return '<figure ' . $id . 'class="post-figure figure-' . esc_attr($align) . '" style="width: '. (int) $width . 'px">' | |
. do_shortcode( $content ) . '<figcaption ' . $capid . 'class="post-figcaption">' . $caption . '</figcaption></figure>'; | |
} | |
add_filter('img_caption_shortcode', 'caption_shortcode', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment