Display Wordpress User Profile information on the page, only when its field is filled in

2

I created fields for social media in the profile editor for a template. I tested on static links and they are working correctly:

 function author_social_media ($profile_fields){

    $profile_fields['facebook'] = 'Facebook URL';

    return $profile_fields;

    $facebookHandle = the_author_meta('facebook');

}

What I'm trying to do is show them only when they're populated, but I'm not succeeding. Completion is not required. I tried the following:

 
<section>    
<?php if(isset($profile_fields['facebook']){
        echo "<a href="<?php the_author_meta('facebook'); ?>">Facebook</a>";
        } else{
        echo '';
        }
?>
</section>

Thank you in advance.

    
asked by anonymous 19.11.2015 / 19:19

1 answer

1

Checks if your test is not coming as an empty%%, since the string command checks only if it is null, according to this link: link

Then do the test like this:

if($profile_fields['facebook'] != "")

Another thing, I noticed that in the code you posted, in isset same, missing closes a parenthesis). Take a look at this too.

    
19.11.2015 / 20:35