Support » Fixing WordPress » Display Author's Twitter Username

  • Resolved Connor Crosby



    I am trying to make an author box that displays the author’s Twitter username if it’s available. I tried copying this code:

    <?php if (get_the_author_url()) { ?><a class="author-website" href="<?php the_author_url(); ?>">Website</a><?php } ?>

    and replacing get_the_author_url() with the_author_meta('twitter') but for some reason it just outputs my Twitter username (and yes I put in the href). How can I get this to work?

    PS: I am not very good with PHP so an explanation would be grateful! 🙂 Thank you!

    I just noticed that get_the_author_url() has been replaced with the_author_meta('user_url') and now that only displays the URL. How can I create an “if statement” for both the website and Twitter username? Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • I have answered my own question after searching online. Probably should have done that first 😉 D’oh! Here it is folks:

    <?php if ( get_the_author_meta( 'twitter' ) ) : ?>
    	<a href="<?php the_author_meta('twitter' );?>">Twitter</a>
    <?php endif; ?>

    Hey Connor !

    Thanks a lot for your post, just helped me figuring out just how to include the twitter meta in my author biography box.

    Cheers !

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display Author's Twitter Username’ is closed to new replies.