Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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