| 1 | /* This removes the built-in caption shortcodes, and replaces them with XHTML-compliant, valid code */ |
|---|
| 2 | remove_shortcode( 'caption' ); |
|---|
| 3 | remove_shortcode('wp_caption'); |
|---|
| 4 | |
|---|
| 5 | function img_caption_shortcode_self($attr, $content = null) { |
|---|
| 6 | |
|---|
| 7 | // Allow plugins/themes to override the default caption template. |
|---|
| 8 | |
|---|
| 9 | $output = apply_filters('img_caption_shortcode_self', '', $attr, $content); |
|---|
| 10 | if ( $output != '' ) |
|---|
| 11 | return $output; |
|---|
| 12 | extract(shortcode_atts(array( |
|---|
| 13 | 'id' => '', |
|---|
| 14 | 'align' => 'alignnone', |
|---|
| 15 | 'width' => '', |
|---|
| 16 | 'caption' => '' |
|---|
| 17 | ), $attr)); |
|---|
| 18 | |
|---|
| 19 | if ( 1 > (int) $width || empty($caption) ) |
|---|
| 20 | return $content; |
|---|
| 21 | |
|---|
| 22 | if ( $id ) $id = 'id="' . $id . '" '; |
|---|
| 23 | return ' <span ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . (10 + (int) $width) . 'px">'. $content . '<span class="wp-caption-text">' . $caption . '</span></span>'; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | add_shortcode('wp_caption', 'img_caption_shortcode_self'); |
|---|
| 27 | add_shortcode('caption', 'img_caption_shortcode_self'); |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | //CSS NEEDED FOR THIS TO WORK PROPERLY |
|---|
| 32 | .wp-caption { |
|---|
| 33 | text-align: center; |
|---|
| 34 | padding-top: 4px; |
|---|
| 35 | } |
|---|
| 36 | .wp-caption img { |
|---|
| 37 | margin: 0 auto; |
|---|
| 38 | padding: 0; |
|---|
| 39 | border: 0 none; |
|---|
| 40 | } |
|---|
| 41 | .wp-caption .wp-caption-text { |
|---|
| 42 | display: block; |
|---|
| 43 | font-size: 11px; |
|---|
| 44 | line-height: 22px; |
|---|
| 45 | margin: 0; |
|---|
| 46 | padding: 0 3px 3px 0; |
|---|
| 47 | color: #fff; |
|---|
| 48 | text-align: center; |
|---|
| 49 | } |
|---|