Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode('wp_caption', 'linktxt_img_caption_shortcode');
- add_shortcode('caption', 'linktxt_img_caption_shortcode');
- function linktxt_img_caption_shortcode($attr, $content = null) {
- // Allow plugins/themes to override the default caption template.
- $output = apply_filters('img_caption_shortcode', '', $attr, $content);
- if ( $output != '' )
- return $output;
- extract(shortcode_atts(array(
- 'id' => '',
- 'align' => 'alignnone',
- 'width' => '',
- 'caption' => ''
- ), $attr));
- if ( 1 > (int) $width || empty($caption) )
- return $content;
- if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
- $frame_width = 5; // frame width in pixels per side //
- global $post;
- preg_match('#(href=\")(.*)(\">)#e',$content,$link); //extract any link from the image
- if( $link[2]) :
- return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . ( 2 * $frame_width + (int) $width) . 'px">'
- . do_shortcode( $content ) . '<p class="wp-caption-text"><a href="' . $link[2] . '">' . $caption . '</a></p></div>';
- else :
- return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . ( 2 * $frame_width + (int) $width) . 'px">'
- . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
- endif;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement