richardshepherd / TwentyTenFive

Updates the WordPress TwentyTen theme to HTML5

Home Page:http://twentytenfive.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WordPress alignment classes are not applied in twentyten_img_caption_shortcode()

csasbach opened this issue · comments

The align attribute of the caption shortcode is never applied to the class of the figure element.

As a workaround I implemented the following in my child theme:

/* FIX TWENTY TEN FIVE CAPTION IMAGE ALIGNMENTS */

/**

  • FIXED The TwentyTen Five Caption shortcode.
  • added by Richard Shepherd to include HTML5 goodness
  • FIXED by C. Scott Asbach to align caption images properly
    *
  • The supported attributes for the shortcode are 'id', 'align', 'width', and
  • 'caption'.
    *
  • @SInCE piddantic 2.0
    */

add_action('init', 'fix_ttf_shortcodes');
function fix_ttf_shortcodes(){
remove_shortcode('twentyten_img_caption_shortcode');
remove_shortcode('twentyten_img_caption_shortcode');
add_shortcode('wp_caption', 'fixed_twentyten_img_caption_shortcode');
add_shortcode('caption', 'fixed_twentyten_img_caption_shortcode');
}
function fixed_twentyten_img_caption_shortcode($attr, $content = null) {

extract(shortcode_atts(array(
    'id'    => '',
    'align' => 'alignnone',
    'width' => '',
    'caption' => ''
), $attr));

if ( 1 > (int) $width || empty($caption) )
    return $content;

if ( $id ) $idtag = 'id="' . esc_attr($id) . '" ';
$align = 'class="' . esc_attr($align) . '" ';

return '<figure ' . $idtag . $align . 'aria-describedby="figcaption_' . $id . '" style="width: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '

' . $caption . '';
}

/* */

To fix Twenty Ten Five directly just add the shortcode's align attribute inside a class attribute for the figure element. Like this:

$align = 'class="' . esc_attr($align) . '" ';

return '<figure ' . $idtag . $align . 'aria-describedby="figcaption_' . $id . '" style="width: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '

' . $caption . '';

Let me know if my fix brakes something else, it didn't for me:P

Sorry for the weird formatting, I'm a noob to github.