Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Add credit-class to image captions
- Description: By adding ":credits-caption:" into your image caption, the class "credits-caption" will get added to the div surrounding the image.
- Author: Jan Dembowski
- Author URI: http://blog.dembowski.net/
- */
- add_filter( 'img_caption_shortcode', 'mh_caption_class_hack', 10, 3 );
- function mh_caption_class_hack( $output, $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) . '" ';
- if ( !preg_match( '/:credits-caption:/' , $caption . '/' , $mh_dont_care ) ) {
- return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
- . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
- } else {
- $caption = str_replace( ':credits-caption:', '' , $caption );
- return '<div ' . $id . 'class="wp-caption credits-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
- . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement