I have an e-learning website that issues an official certificate of completion when a students complete their training course. The user profile name on the account can be used as the student name when generating the certificate, but if the user updates their profile name it also updates the name on the certificate. This is a problem since it would allow a user to complete a course once and then update their user profile name multiple times to generate official certificates for several other people(without completing the training or paying for it).

I created a set of custom user meta fields for the student name that are only exposed on the back end and I changed the certificate setup so that it uses these custom meta fields to add the student name to the certificate. The custom meta field remains blank if I don't manually update it on the back end, but I want the user to be able to enter this information on the front end for themselves once and then prevent any future updates from the front end (only allow me to make approved updates on the back end).

How do I expose a custom user meta input field on the front end user profile page only if it is empty and then hide it if it's not null?

  • You can just check for meta value and hide the meta field if value exists. Jun 6, 2020 at 15:25

1 Answer 1


You could very easily do a check to see if that field already had a value in the database and if it does, display the name, if it doesn't, display a form field. You haven't provided any code so my example below is a really loose snippet of pseudo-code showing the the method.

    $current_user = get_current_user_id();
    $student_name = get_user_meta( $current_user, 'student_name', true );
    if( !empty( $student_name ) ) :
        echo '<span class="student_name_provided">' . $student_name . '</span>';
    else :
        echo '<input type="text" name="student_name" id="student_name" value=""/>';

So if !empty() or not empty, then it displays the value of the student_name user meta in a span tag that you can style however you like.

But, if the check returns an empty value for student_name it instead loads a text input field where the student can then provide their name.

Now all of this would need to be incorporated with whatever other front end editable stuff you've got set up, but the if( !empty() ) : conditional check is the key aspect because it allows you to change what you provide the user with on the front end.

Hope that helps.

  • Thank you Tony! I'll give it a try. Jun 8, 2020 at 13:33
  • That works just like I need it too. Thanks again! Jun 12, 2020 at 17:27
  • Awesome. Glad I could help. 😊 Jun 12, 2020 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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