How to display public user profile with 2 additional fields? (GitHub source code included)

As a WordPress newbie I am trying to create a plugin, which will force users to specify their city and gender while registering and then display a personal profile page for each user showing this information.

I have checked in my plugin in GitHub: wp-city-gender.php.

For the registration part I have followed the Customizing the Registration Form doc and it seems to work fine – the additional city and gender fields are displayed in the registration form and stored later in the wp_usermeta table. They are also editable in the Users part of the dashboard:

Users screenshot

Also, I redirect commenter links to /user/user_id by using this code:

define('PROFILE', '<a href="/user/%d" rel="external nofollow" class="url">%s</a>');

function get_comment_author_link($cid) {
    global $comment;
    return sprintf(PROFILE, $comment->user_id, $comment->comment_author);

add_action('get_comment_author_link',  'get_comment_author_link');


My question is: How can I add a personal profile page for each user, displaying his/her name and the 2 additional fields?

What I don’t want: I can not just create a plain PHP script fetching data from wp_usermeta for a certain numeric user_id – because it wouldn’t be integrated in my WordPress website, i.e. it won’t display the logo at the top and the footer at the bottom.

Solutions Collecting From Web of "How to display public user profile with 2 additional fields? (GitHub source code included)"

I think an easy way to do this would be to make use of the wordpress template structure, take a look at Codex: Templates and Codex: Template Hierarchy for a general overview. But namely you could use the author templates – Codex: Author Templates – for this, so likely you will adapt the author.php file to fit your needs.

Additionally you want to change the rewrite structure for the author template to match your goals. General information can be found at Codex: Rewrite API and Codex: Class Reference/WP_Rewrite. Besides that this has been answered several times here on WPSE, no need to duplicate this, so take a look at: Diplay a registered user profile page and/or How to custom change author base without $this->front?.

I tried to create a custom form registration a while ago using wordpress. I wanted to register several custom fields and make them required so I tried to find the right plugin instead of reinventing the wheel.

I found a good plugin called theme my login:

You will need to read a bit to do this, but lucky us there’s documentation that can help you on this website:

See here how to add extra registration fields:

Basically you need to:

1) Install the plugin

2) Add register-form.php into your theme layout.

3) Modify your copy of your register-form.php For something like this:

<div class="login" id="theme-my-login<?php $template->the_instance(); ?>">

<?php $template->the_action_template_message( 'register' ); ?>
<?php $template->the_errors();  

<form name="registerform" id="registerform<?php $template->the_instance(); ?>" action="<?php $template->the_action_url( 'register' ); ?>" method="post" autocomplete = "off">

    <input type="text" name="user_login" id="user_login<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'user_login' ); ?>" size="20" />
    <input type="text" name="user_email" id="user_email<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'user_email' ); ?>" size="20" />
    <input type="text" placeholder="Gender" name="user_gender" id="user_gender<?php $template->the_instance(); ?>" value="<?php $template->the_posted_value( 'user_gender' ); ?>" required />
    <input type="text" placeholder="City" type="text" id="user_city<?php $template->the_instance(); ?>" name="user_city" value="<?php $template->the_posted_value( 'user_city' ); ?>"/>

    <?php do_action( 'register_form' ); ?>

    <p class="submit">
        <input type="submit" name="wp-submit" class="yellow btn1 uppercase right os700" id="wp-submit<?php $template->the_instance(); ?>" value="<?php esc_attr_e( '[ Submit ]' ); ?>" />
        <input type="hidden" name="redirect_to" value="<?php $template->the_redirect_url( 'register' ); ?>" />
        <input type="hidden" name="instance" value="<?php $template->the_instance(); ?>" />
        <input type="hidden" name="action" value="register" />
<?php $template->the_action_links( array( 'register' => false ) ); ?>

Here you can modify and add custom fields and as much HTML and CSS as you want/need.

Then on your functions.php you will need to register a couple of actions so you here we go.

To register the user:

function tml_user_register( $user_id ) {
    if ( !empty( $_POST['user_login'] ) )
        update_user_meta( $user_id, 'user_login', $_POST['user_login'] );
    if ( !empty( $_POST['user_email'] ) )
    update_user_meta( $user_id, 'user_email', $_POST['user_email'] );
    if ( !empty( $_POST['user_gender'] ) )
        update_user_meta( $user_id, 'user_gender', $_POST['user_gender'] );
    if ( !empty( $_POST['user_city'] ) )
        update_user_meta( $user_id, 'user_city', $_POST['user_city'] );


add_action( 'user_register', 'tml_user_register' );`

To display the content on the dashboard:

add_action ( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action ( 'edit_user_profile', 'my_show_extra_profile_fields' );

With these two actions you can display your user profiles on your dashboard so add this in your functions.php as well.

    <?php function my_show_extra_profile_fields ( $user ){ ?>
    <h3>Custom profile information</h3>
    <table class="form-table">
            <th><label for="user_gender"><?php _e('Gender');?></label></th> 
            <td><input type="text" name="user_gender" id="user_gender" value="<?php echo esc_attr( get_the_author_meta( 'user_gender', $user->ID ) ); ?>" /><br /></td>
            <th><label for="user_city"><?php _e('City');?></label></th>
            <td><input type="text" name="user_city" id="user_city" value="<?php echo esc_attr( get_the_author_meta( 'user_city', $user->ID ) ); ?>" /><br /></td>

<?php }

If you want to let the users update their own info add something like this (also in your functions.php):

add_action ( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action ( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id ){
    if ( !current_user_can( 'edit_user', $user_id ) )
        return false;
    update_usermeta( $user_id, 'user_gender', esc_attr(trim($_POST['user_gender'])) );
    update_usermeta( $user_id, 'user_city', esc_attr(trim($_POST['user_city'])) );


Is quite a lot, but useful have a go, read the documentation and good luck, hope this helps you.


Ok so if you want to show the user meta you can use the author.php and the profile-form.php located in the templates folder, as well as with the register-form.php other files you can copy this file into your theme folder and customise.

To display the custom meta on your author.php add the following shortcode:

echo do_shortcode('[theme-my-login default_action="profile" show_title="1"]');

Then you can show the content using something like this:

echo $profileuser->user_city
echo $profileuser->user_gender

You are making some assumptions about WordPresses user system that are incorrect.

author_link and comment_author_link return the value that people provide in the website field when leaving a comment or on their user profile (if they have signed up). These fields may also be empty, but virtually always will point to an external site if set.

It does in no way link to a profile page, WordPress by default does not do profile pages, hence why people have created a lot of plugins around this idea (from simple profile pages right up to things like buddy press).

Author.php is an archive for the Author’s posts, and a user !== author

If you would like to have public user profile pages and custom fields on profiles, I highly suggest using one of the many plugins designed to do it already – to set it up is not a simple function or ‘quick’ fix, and you can’t expect someone to do that amount of work for you for +50 internet points.