Support » Fixing WordPress » Trim text in custom field

  • Is is possible to trim text from custom field?

    I wanna show part of text which is entered in custom field. Any way to show trimmed text in theme? Any function similar to wp_trim_excerpt?

Viewing 1 replies (of 1 total)
  • I was looking for the same thing. The code below should do the trick:

    <?php
    $trim_length = 5;  //desired length of text to display
    $custom_field = 'my-custom-field-name';
    $value = get_post_meta($post->ID, $custom_field, true);
    if ($value) {
     echo rtrim(substr($value,0,$trim_length));
    }
    ?>

    Worked perfectly for me!

Viewing 1 replies (of 1 total)
  • The topic ‘Trim text in custom field’ is closed to new replies.