Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- remove_shortcode('wp_caption');
- remove_shortcode('caption');
- add_shortcode('wp_caption', 'custom_img_caption_shortcode');
- add_shortcode('caption', 'custom_img_caption_shortcode');
- function custom_img_caption_shortcode($attr, $content = null) {
- //output image title above caption field//
- // New-style shortcode with the caption inside the shortcode with the link and image tags. wp3.4
- if ( ! isset( $attr['caption'] ) ) {
- if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {
- $content = $matches[1];
- $attr['caption'] = trim( $matches[2] );
- }
- }
- extract(shortcode_atts(array(
- 'id' => '',
- 'align' => 'alignnone',
- 'width' => '',
- 'caption' => ''
- ), $attr));
- if ( 1 > (int) $width || empty($caption) )
- return $content;
- if ( $id ) { $img_id = array_pop(explode('_',$id)); $id = 'id="' . esc_attr($id) . '" '; }
- $framewidth = 5; // frame width in px per side; default is 5 //
- $output = '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . ( 2 * $framewidth + (int) $width) . 'px">';
- $output .= do_shortcode( $content );
- $title = ''; //extract the image title with preg_match_all from $content
- if ( preg_match_all( '#(title=")(.*)(" )#U', $content, $matches, PREG_PATTERN_ORDER ) ) {
- $title = str_replace(array('title="','"'),'',$matches[0][0]);
- }
- if( $title ) $output .= '<span class="caption-image-title">' . $title . '</span>';
- $output .= '<p class="wp-caption-text">' . $caption . '</p></div>';
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement