WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display Author's Twitter Username (3 posts)

  1. Connor Crosby
    Member
    Posted 2 years ago #

    Hello,

    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 twitter.com/ 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!

    EDIT:
    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!

  2. Connor Crosby
    Member
    Posted 2 years ago #

    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="http://twitter.com/<?php the_author_meta('twitter' );?>">Twitter</a>
    <?php endif; ?>
  3. Theo_1
    Member
    Posted 1 year ago #

    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 !

Topic Closed

This topic has been closed to new replies.

About this Topic