Author Bio Excerpt

When you like to show a short intro of the author bio of a post and not his complete bio. Use this code snippet to make an excerpt of the bio, with a link to the author page, where you can show the full bio.


// Add this code snippet to the single.php file where you like to display the author bio excerpt. <br />
echo author_excerpt();

Code Snippet:

// Paste the code below to the functions.php file inside the theme directory you're using.
function author_excerpt (){	                     					
	$word_limit = 20; // Limit the number of words
	$more_txt = 'read more about:'; // The read more text
	$txt_end = '...'; // Display text end 
	$authorName = get_the_author();
	$authorUrl = get_author_posts_url( get_the_author_meta('ID'));
	$authorDescription = explode(" ", get_the_author_meta('description'));
	$displayAuthorPageLink = count($authorDescription) > $word_limit ? $txt_end.' '.$more_txt.' <a href="'.$authorUrl.'">'.$authorName.'</a>' : '' ;
	$authorDescriptionShort = array_slice($authorDescription, 0, ($word_limit));
	return (implode($authorDescriptionShort, ' ')).$displayAuthorPageLink; 		

Posted in Posts