WordPress.org

Ready to get started?Download WordPress

Forums

How to assign the_author_description to variable (3 posts)

  1. robertlove
    Member
    Posted 7 years ago #

    Is there a way to assign the author's description to a variable in order to output an "About the Author" section if it is not empty?

    I've got this far:

    <?php $userdata = get_userdata(1); ?>
    <?php if ($userdata->description != '') { ?>
    <h2>About the Author</h2>
    <p><?php _e($userdata->description); ?></p>
    <?php } ?>

    But can't find a way to get the author_id within the loop in order to pass it to the get_userdata function.

  2. robertlove
    Member
    Posted 7 years ago #

    In the loop:

    <?php $author_id = get_the_author_ID(); ?>

    Then, wherever you want to output:

    <?php $userdata = get_userdata($author_id); ?>
    <?php if ($userdata->description != '') { ?>
    <h2>About the Author</h2>
    <p><?php _e($userdata->description); ?></p>
    <?php } ?>

    Thanks for the heads up on get_the_author_ID() Ei Sabai. Who needs the experts when I have you sitting in the next office :)

  3. tbplayer
    Member
    Posted 6 years ago #

    Just wanted to say thanks for posting the solution - it helped me solve a problem I was having with userdata->description.

Topic Closed

This topic has been closed to new replies.

About this Topic