Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 05 jan 2013 alchymyth
- // show thumbnail with post title as 'caption', wrapped with '.wp-caption thumb-caption' div;
- add_filter('post_thumbnail_html','add_post_thumbnail_post_title_as_caption',10,5);
- function add_post_thumbnail_post_title_as_caption($html, $post_id,
- $post_thumbnail_id, $size, $attr) {
- if( $html == '' ) {
- return $html;
- } else {
- $out = '';
- global $post;
- $thumbnail_image = get_posts(array('p' => $post_thumbnail_id,
- 'post_type' => 'attachment'));
- if ($thumbnail_image && isset($thumbnail_image[0])) {
- $image = wp_get_attachment_image_src($post_thumbnail_id, $size);
- $t_width = $image[1] +0; // +0 here for no extra padding, needs to be considered in writing css - the default image caption uses +10;
- $class = $attr['class'];
- $out .= '<div
- class="wp-caption thumb-caption '.$class.'"
- style="width:'.$t_width.'px; ">';
- $out .= $html;
- $out .= '<p
- class="wp-caption-text">'.apply_filters('the_title',$post->post_title).'</p></div>';
- }
- return $out;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement