Forums

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

  1. ccmovies
    Member
    Posted 3 months 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. ccmovies
    Member
    Posted 3 months 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; ?>

Reply

You must log in to post.

About this Topic