Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to only display the author's name and description (aka bio) if the description contains text?

This code doesn't work (it doesn't return the name or description) but hopefully it can be edited to accomplish this goal:

<?php
$authorDesc = the_author_meta($post->ID, 'description', true);
if (!empty($authorDesc)) {
?>
<em>by <?php the_author(); ?></em>
<span><?php the_author_meta('description'); ?></span>
<?php } ?>
share|improve this question

2 Answers 2

up vote 2 down vote accepted
<?php
$authordesc = get_the_author_meta( 'description' );

if ( ! empty ( $authordesc ) )
{
?>
    <a href="<?php
    echo get_author_posts_url( get_the_author_meta( 'id' ) );
    ?>"><?php
    the_author();
    ?></a>
    <?php
    echo wpautop( $authordesc );
}
share|improve this answer
    
Perfect - thank you! –  Ryan Mar 9 '11 at 0:32

First, you need to use get_the_author_meta instead of the_autho_meta to give a vakue to $authorDesc (get_the_author_meta returns the value, the_author_meta displays it).

Secondly, you need to use user_description as the argument for both functions instead of description.

Hope it works.

EDIT - Here is the documentation to the_author_meta for more info. EDIT 2 - You also don't need to declare $post->ID as the first parameter for the_author_meta. Are you using it inside the loop?

share|improve this answer
    
Yes, I'm using this inside the loop. I tried your edits but can't seem to get it working: <?php $authorDesc = get_the_author_meta('','user_description', true); if (!empty($authorDesc)) { ?> <em>by <?php the_author(); ?></em> <span><?php get_the_author_meta('user_description'); ?></span> <?php } ?> –  Ryan Mar 5 '11 at 0:18
    
@Ryan - Forgot to mention, try to use get_the_author_meta=("user_description"),without true. And, in the second run,in the span, you need to either echo get_the_user_meta or use the_author_meta (no get). –  Cronco Mar 5 '11 at 0:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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