WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've added some extra $curauth fields to the user profile page via ths method:

function change_contactmethod( $contactmethods ) {

$contactmethods['twitter'] = 'Twitter URL';

// more $contactmethods go here

return $contactmethods;


And they are displayed this way on the author.php template, which only displays the link if it is entered in te user profile:

<?php echo $curauth->twitter; ?>

But what I need to do is determine if the curauth field exists before display, as I want to turn the twitter URL into a linked image. Calling $curauth->twitter; as above with a linked image still displays the image if no link is entered in the users profile.

This is what I'm trying with no luck:

<?php $my_post_meta = get_post_meta($post->ID, 'twitter', true);
if ( ! empty ( $my_post_meta ) )
    echo '<a href=" '.$my_post_meta.' "><img src="<?php bloginfo(\'template_url\'); ?>/images/twitter.png"></a>'; ?>

Update 12/23/11 - This now works:

<?php if ( !empty( $curauth->twitter ) ) { echo '<a href=" ' . $curauth->twitter . '"><img src="' . get_bloginfo('template_url') . '/images/twitter.png"></a>'; } ?>
share|improve this question
up vote 2 down vote accepted

Use the empty() check on them.

if ( !empty( $curauth->twitter ) ) {
  // do stuff 

This is best practice since empty avoids the property not existing error.

share|improve this answer
Ah, good point. Works fine now. – markratledge Dec 23 '11 at 20:57

get_post_meta is used for posts and won't retrieve author information.

You'll need to use get_the_author_meta('twitter');.

In this case on the author.php page :

$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) :  get_userdata(intval($author));
    if ($curauth->twitter)  {
        echo '<a href=" ' . $curauth->twitter . '"><img src="' . get_bloginfo('template_url') . '/images/twitter.png"></a>';
share|improve this answer
Hmm.... No luck with that. No errors, either. – markratledge Dec 23 '11 at 19:57
What about that code? Based off of: codex.wordpress.org/Author_Templates – CookiesForDevo Dec 23 '11 at 20:04
Your edit works better, but as per Otto above, it needs the !empty operator, i.e. : <?php if ( !empty( $curauth->twitter ) ) { echo '<a href=" ' . $curauth->twitter . '"><img src="' . get_bloginfo('template_url') . '/images/twitter.png"></a>'; } ?> – markratledge Dec 23 '11 at 20:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.