Only display link to author social media when it exists

I’ve added the following code to my functions.php to expand the functionality of the user profile page and be able to add links to the social media of the authors.

function my_new_contactmethods( $contactmethods ) {
// Add Site
$contactmethods['mysite'] = 'My Site';
// Add Google Plus
$contactmethods['google_plus'] = 'Google Plus';
// Add Behance
$contactmethods['behance'] = 'Behance';
// Add Twitter
$contactmethods['twitter'] = 'Twitter';
//add Facebook
$contactmethods['facebook'] = 'Facebook';
return $contactmethods;

On the author.php I call the links like this:

<a title="Follow me on Twitter" href="<?php the_author_meta( 'twitter', $author_id ); ?>"><img src="twitter.png" alt="" /></a>
<a title="Follow me on Facebook" href="<?php the_author_meta( 'facebook', $author_id ); ?>"><img src="facebook.png" alt="" /></a>
<a title="Follow me on Behance" href="<?php the_author_meta( 'behance', $author_id ); ?>"><img src="behance.png" alt="" /></a>
<a title="Follow me on Google+" href="<?php the_author_meta( 'google_plus', $author_id ); ?>"><img src="google-plus.png" alt="" /></a>

The problem with this solution is that it shows the image and link even if the author has not filled the corresponding field.

Would it be some easy way to just echo the links that have been previously filled?

Solutions Collecting From Web of "Only display link to author social media when it exists"

This is a very simple PHP issue, unrelated to WordPress. You need to check if the value is empty before echoing it. So, store them as variables first:

$twitter  = get_the_author_meta('twitter', $author_id);
$facebook = get_the_author_meta('facebook', $author_id);

Then check them before displaying:

if(!empty($twitter)) {
    echo '<a title="Follow me on Twitter" href="'.$twitter.'"><img src="twitter.png" alt="" /></a>';
if(!empty($facebook)) {
    echo '<a title="Follow me on Facebook" href="'.$facebook.'"><img src="facebook.png" alt="" /></a>';