WordPress tip: author bio excerpt

Let’s start by creating the function. The code below have to be pasted into your functions.php file.

 <?php 	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')); 		$  authorDescriptionShort = wp_trim_words(strip_tags(get_the_author_meta('description')), $  word_limit, $  txt_end.'<br /> '.$  more_txt.' <a href="'.$  authorUrl.'">'.$  authorName.'</a>'); 		return $  authorDescriptionShort; 		 	} ?>

Once done, you can use the function. To do so, use the code below where you’d like to display an author bio excerpt:

<?php  if (function_exists('author_excerpt')){echo author_excerpt();} ?>

Thanks to Tim Marcher for submitting this recipe!

Web Design

authorexcerptWordPress

Leave a Reply

Your email address will not be published. Required fields are marked *