⏲️ 3 minutes

How to Add A Title Field To User Profiles In WordPress

The code snippet plugin changed my life. I no longer edit the raw PHP files to add simple functions like titles to users' profiles.
Image of a title field

In the tutorial below, I'll share three ways to create, call, and display a given author's job title in WordPress posts using the free version of the Code Snippet Plugin. All you have to do is copy and paste the code provided.

Using Oxygen Page Builder

Here's how you can add the title field to user profiles using the Code Snippets plugin.

  1. Install and activate the Code Snippets plugin on your WordPress site.
  2. Go to Snippets > Add New to create a new snippet.
  3. Copy the following PHP code into the Code field.
// Add a title field to the user profile
function add_title_field_to_profile($user){
?>
  <table class="form-table">
    <tr>
      <th><label for="title">Title</label></th>
      <td>
        <input type="text" name="title" id="title" value="<?php echo esc_attr(get_the_author_meta('title', $user->ID)); ?>" class="regular-text" /><br />
        <span class="description">Please enter your title.</span>
      </td>
    </tr>
  </table>
<?php
}
add_action('show_user_profile', 'add_title_field_to_profile');
add_action('edit_user_profile', 'add_title_field_to_profile');

// Save the title field when the user profile is saved
function save_title_field($user_id){
  if (!current_user_can('edit_user', $user_id)) {
    return false;
  }
  update_user_meta($user_id, 'title', $_POST['title']);
}
add_action('personal_options_update', 'save_title_field');
add_action('edit_user_profile_update', 'save_title_field');
  1. Give your snippet a title (e.g. "Add Title Field to User Profiles") and click the "Save Changes and Activate" button.
  2. To display the title on the front end, go to Oxygen Builder and create a new template or edit an existing one.
  3. Add a Dynamic Data shortcode in the template and select "Author Meta" as the source.
  4. In the "Key" field, enter "title".
  5. Customize the title display by adding text, HTML, and CSS around the shortcode as desired.
  6. Preview the template to see the user's title displayed on the front end.

This code uses the get_the_author_meta function to retrieve the user's title from the database and display it in Oxygen Builder.

Using The Block Editor

Here's an example of how you can add a title field to user profiles in WordPress using the Code Snippets plugin and display it on the front end using the block editor:

  1. Install and activate the Code Snippets plugin on your WordPress site.
  2. Go to Snippets > Add New to create a new snippet.
  3. Add the following code to the snippet:
function add_title_field_to_profile( $user ) {
    ?>
    <table class="form-table">
        <tr>
            <th><label for="title">Title</label></th>
            <td>
                <input type="text" name="title" id="title" value="<?php echo esc_attr( get_the_author_meta( 'title', $user->ID ) ); ?>" class="regular-text" /><br />
                <span class="description">Please enter your title</span>
            </td>
        </tr>
    </table>
    <?php
}
add_action( 'show_user_profile', 'add_title_field_to_profile' );
add_action( 'edit_user_profile', 'add_title_field_to_profile' );

function save_title_field_to_profile( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) ) {
        return false;
    }
    update_user_meta( $user_id, 'title', $_POST['title'] );
}
add_action( 'personal_options_update', 'save_title_field_to_profile' );
add_action( 'edit_user_profile_update', 'save_title_field_to_profile' );
  1. Give your snippet a title (e.g. "Title Field in User Profile") and click the "Save Changes and Activate" button.
  2. Create a new page or post using the block editor.
  3. Add a "Shortcode" block to the page or post.
  4. In the Shortcode block, add the following shortcode to display the title field:
[display_title_field]

Using A Shortcode

Here's an example of how you can add a title field to user profiles in WordPress using the Code Snippets plugin and display it on the front using a shortcode:

  1. Install and activate the Code Snippets plugin in your WordPress site.
  2. Go to Snippets > Add New to create a new snippet.
  3. Add the following code to the snippet:
function add_title_field_to_profile( $user ) {
    ?>
    <table class="form-table">
        <tr>
            <th><label for="title">Title</label></th>
            <td>
                <input type="text" name="title" id="title" value="<?php echo esc_attr( get_the_author_meta( 'title', $user->ID ) ); ?>" class="regular-text" /><br />
                <span class="description">Please enter your title</span>
            </td>
        </tr>
    </table>
    <?php
}
add_action( 'show_user_profile', 'add_title_field_to_profile' );
add_action( 'edit_user_profile', 'add_title_field_to_profile' );

function save_title_field_to_profile( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) ) {
        return false;
    }
    update_user_meta( $user_id, 'title', $_POST['title'] );
}
add_action( 'personal_options_update', 'save_title_field_to_profile' );
add_action( 'edit_user_profile_update', 'save_title_field_to_profile' );

function display_title_field() {
    global $post;
    $user_id = $post->post_author;
    $title = get_the_author_meta( 'title', $user_id );
    return $title;
}
add_shortcode( 'display_title_field', 'display_title_field' );
  1. Give your snippet a title (e.g. "Title Field in User Profile") and click the "Save Changes and Activate" button.
  2. Create a new page or post and add the following shortcode to display the title field:
[display_title_field]
  1. Save your changes and preview the front end to see the title field displayed on the page or post.

With this code, a title field will be added to the user profile section in the WordPress backend and can be displayed on the front end using a shortcode.

About the author

January 29, 2023
Cedric Chambers is a humble polymath. He studied painting as an undergraduate and business analytics in his master's program. Throughout the past decade, Cedric has worked in a number of industries.
December 23, 2023
The Importance of Quality Score for CPC

The results are surprising, Quality Score and Cost Per Click are more clearly correlated when you look at Exact Match keywords.

Read More
January 29, 2023
How To Style The WordPress Code Block

I love WordPress for its customizations. Styling code snippets enhances user perceptions. Copy and paste the code below to style your WordPress code blocks.

Read More
January 29, 2023
How to Add A Title Field To User Profiles In WordPress

The code snippet plugin changed my life. I no longer edit the raw PHP files to add simple functions like titles to users' profiles.

Read More
December 24, 2022
Adwords: Reducing CPA by 59%

By restructuring your account and using hyper-targeted ad text, CPA can be reduced.

Read More
December 16, 2022
The Meaning + Examples Of YMYL Pages

YMYL stands for "Your Money or Your Life." Google uses YMYL to help understand if a web page's main content could impact people's safety, health, or financial well-being.

Read More
December 15, 2022
A/B Testing With Optinmonster: Increasing Revenue By 64.89%

With slight modifications to Optinmonster's native A/B testing capabilities, it becomes an excellent CRO testing tool.

Read More
  • Lubble Favicon
  • OUR BLOG
    December 23, 2023
    The Importance of Quality Score for CPC

    The results are surprising, Quality Score and Cost Per Click are more clearly correlated when you look at Exact Match keywords.

    Read More
    January 29, 2023
    How To Style The WordPress Code Block

    I love WordPress for its customizations. Styling code snippets enhances user perceptions. Copy and paste the code below to style your WordPress code blocks.

    Read More
    January 29, 2023
    How to Add A Title Field To User Profiles In WordPress

    The code snippet plugin changed my life. I no longer edit the raw PHP files to add simple functions like titles to users' profiles.

    Read More
    December 24, 2022
    Adwords: Reducing CPA by 59%

    By restructuring your account and using hyper-targeted ad text, CPA can be reduced.

    Read More
    December 16, 2022
    The Meaning + Examples Of YMYL Pages

    YMYL stands for "Your Money or Your Life." Google uses YMYL to help understand if a web page's main content could impact people's safety, health, or financial well-being.

    Read More
    December 15, 2022
    A/B Testing With Optinmonster: Increasing Revenue By 64.89%

    With slight modifications to Optinmonster's native A/B testing capabilities, it becomes an excellent CRO testing tool.

    Read More
    Lubble's mission is to be the go-to resource for digital marketers and local business owners.
    Insights