public
Last active

T5 Caption With Description

  • Download Gist
caption-with-description.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 Caption With Description
* Description: Adds the description to images with a caption.
* Version: 2012.04.06
* Author: Thomas Scholz <info@toscho.de>
* Author URI: http://toscho.de
* License: MIT
* License URI: http://www.opensource.org/licenses/mit-license.php
*/
 
add_filter( 'img_caption_shortcode', 't5_caption_with_description', 10, 3 );
 
function t5_caption_with_description( $dummy, $attr, $content )
{
extract(
shortcode_atts(
array (
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => '',
'desc' => 1
),
$attr
)
);
 
if ( 1 > (int) $width || empty ( $caption ) )
return $content;
 
if ( $id )
{
$html_id = 'id="' . esc_attr( $id ) . '" ';
$html_desc = '';
 
if ( 1 == $desc )
{
$img = get_post( str_replace( 'attachment_', '', $id ) );
$html_desc = trim( $img->post_content );
if ( '' !== $desc )
{
$html_desc = '<div class="image-description">' . wpautop( $html_desc ) . '</div>';
}
}
}
 
return sprintf(
'<div %1$sclass="wp-caption %2$s" style="width: %3$spx">%4$s%5$s%6$s</div>',
$html_id,
esc_attr( $align ),
10 + (int) $width,
do_shortcode( $content ),
$caption,
$html_desc
);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.