richardshepherd / TwentyTenFive

Updates the WordPress TwentyTen theme to HTML5
http://twentytenfive.com
GNU General Public License v2.0
91 stars 15 forks source link

WordPress alignment classes are not applied in twentyten_img_caption_shortcode() #5

Closed csasbach closed 13 years ago

csasbach commented 13 years ago

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 */

/**

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">' . doshortcode( $content ) . '<figcaption id="figcaption' . $id . '">' . $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">' . doshortcode( $content ) . '<figcaption id="figcaption' . $id . '">' . $caption . '';

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

csasbach commented 13 years ago

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