Skip to content

Instantly share code, notes, and snippets.

@angeliquejw
Created August 20, 2013 20:20
Show Gist options
  • Save angeliquejw/6286743 to your computer and use it in GitHub Desktop.
Save angeliquejw/6286743 to your computer and use it in GitHub Desktop.
Trim custom field in WordPress
<?php
$trim_length = 25; //desired length of text to display
$value_more = '(&hellip;)'; // what to add at the end of the trimmed text
$custom_field = 'my-custom-field-name';
$value = get_post_meta($post->ID, $custom_field, true);
if ($value) {
echo wp_trim_words( $value, $trim_length, $value_more);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment