3

How can I change the 'Caption' text input to text area, to allow for multi line captions on media uploads?

1

I don't think you can do that, however you can implement this code in your functions file to at least allow for line breaks in single image captions

Note: doesn't work for gallery images (I am trying to find a way to make it work in galleries)

/*
*********************************************
Function to allow multi-line photo captions.
This function will split captions onto multiple lines if it detects
a "|" (pipe) symbol.
**********************************************
*/
/* Override existing caption shortcode handlers with our own */
add_shortcode('wp_caption', 'multiline_caption');
add_shortcode('caption', 'multiline_caption');

/* Our new function */
function multiline_caption($attr, $content = null) {
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) . '" ';

$new_caption = str_replace("|", "<br />", $caption);

return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $new_caption . '</p></div>'; }

Original code by Mark Wood: http://digitalnotions.net/multi-line-captions-in-wordpress

  • Did that work for you? If that's helpful, please accept! Thanks – Sol Mar 14 '12 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.