Question

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 } ?>
Was it helpful?

Solution

<?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 );
}

OTHER TIPS

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top