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

Asked

Viewed 49 times

2

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

 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 filled in, but I’m not succeeding. Filling in is not required. I tried it this way:

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

Grateful from now on.

1 answer

1


Check if your test is not coming as a string empty as the command isset only checks if it is null, according to this link: http://php.net/manual/en/function.isset.php

So take the test like this:

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

Another thing, I noticed that in the code you posted on IF same, missing closes a parentheses ")". Take a look at this too.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.