How to Add User Contact Fields in WordPress

Categories Components, Tutorials, Users
Add User Contact Fields in WordPress

Every user profile in WordPress has few user contact fields that can be used to display to their user or author profile. There used to be fields for some social networks, such as Yahoo IM and Jabber, in the past but WordPress has removed it from its core since.

You can extend the profile contact fields by adding more fields using the user_contactmethods filter.

Adding User Contact Fields

WordPress User Contact Fields

You can add the following code to the functions.php file of your active theme:

The above code will add Facebook and Twitter fields to user profile’s contact section. Later you can show these values in user’s author profile using a diffrent function.

Retrieving User Contact Fields

You can use get_the_author_meta() function to retrieve the saved values. These values can be displayed in your user’s profile or below their posts in the author profile.

You need to pass the field and ID of the user to the function to get its value. You can use the following function to get the value of the Twitter field:

Do not forget to replace twitter in the above code with other fields, such as description or facebook, to get their values.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.