1
<p><?php the_author_meta('description'); ?></p>

We use the above to pull the author's description, but is there a way through which we can restrict or implement the word limit on the content pulled in the author's description?

1

There is none. You have to implement your own custom function to trim any content you wish. For example, this function will trim your content based on words:

function my_custom_excerpt ( $content, $limit = 20, $more = '...' ){                      
    return $data = wp_trim_words( strip_tags( $content ), $limit, $more );
}

Or this one will trim it based on characters:

function my_custom_excerpt( $excerpt, $limit = 20 ) {
    $charlength++;
    if ( mb_strlen( $excerpt ) > $charlength ) {
        $subex = mb_substr( $excerpt, 0, $charlength - 5 );
        $exwords = explode( ' ', $subex );
        $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
        if ( $excut < 0 ) {
            $output = mb_substr( $subex, 0, $excut );
        } else {
            $output = $subex;
        }
        $output .= ' ...';
        return $output;
    } else {
        return $excerpt;
    }
}

Now you can use:

<p><?php echo my_custom_excerpt( get_the_author_meta('description') , 20 ); ?></p>

Which will trim the author's description by 20 words/characters, based on your function.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.