I want to limit the characters a user is able to enter for the image/attachment caption. There are already long captions in the system and I don't wont to touch them. Any ideas on how to do this? I can't find any plugins available.


do you have a custom meta field associated with the image? if so place this in your functions.php:

$trim_length = 21;  //desired length of text to display
$custom_field = 'your custom field key here';
$value = get_post_meta($post->ID, $custom_field, true);
if ($value) {
  echo '<p>I want to use: ' . rtrim(substr($value,0,$trim_length)) . '...</p>';

this will limit the character count in any meta field just place your meta key in $custom_field='';

hope this helps cheers.

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.