Skip to content

Instantly share code, notes, and snippets.

@ramseyp
Created January 12, 2012 17:31
Show Gist options
  • Save ramseyp/1601913 to your computer and use it in GitHub Desktop.
Save ramseyp/1601913 to your computer and use it in GitHub Desktop.
shorten user descriptions - WordPress
<?php
// filter user description to return something shorter
add_filter ( 'pre_user_description', 's25_short_description' );
function s25_short_description($description) {
$max_characters = 50;
if ( strlen( $description ) > $max_characters ) {
$description = substr( $description, 0, $max_characters + 1 );
$description = trim( substr( $description, 0, strrpos( $description, ' ' ) ) );
}
return $description;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment