0

I’ve added a custom section to the user profile in my own theme. The section is called „Extra Profilinformationen“ for now and includes a field for twitter. It’s added to the bottom. Is there any way to place it before the profile image? How can I change the order of it?

enter image description here

function my_show_extra_profile_fields( $user ) { ?>
  <h3>Extra Profilinformationen</h3>
  <table class="form-table">
    <tr>
      <th><label for="twitter">Twitter</label></th>
      <td>
        <input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
        <p class="description">Füge ein Twitterprofil hinzu.</p>
      </td>
    </tr>
  </table>
<?php }
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_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, 'twitter', $_POST['twitter'] );
}
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
3
  • You should probably include the code used to create the extra profile fields. Commented Jan 2, 2020 at 15:47
  • You probably want to add Twitter as a user_contactmethod, e.g. Yoast's code. These appear at the bottom of 'Contact Info', above 'About Yourself'.
    – Rup
    Commented Jan 2, 2020 at 16:08
  • @RiddleMeThis I’ve added the code I used.
    – DKX
    Commented Jan 3, 2020 at 11:28

1 Answer 1

1

Unfortunately there's no action hooks on user-edit.php that would allow you to place html before the profile image. One option is to use javascript/jquery to move the html around the profile page.

But as @RiddleMeThis mentioned on the comments, you can use user_contactmethods filter to add custom contact methods such as Twitter to the profile page.

add_filter('user_contactmethods', 'my_user_contactmethods');

function my_user_contactmethods($contactmethods){

  $contactmethods['twitter'] = __('Twitter Username', 'textdomain');

  return $contactmethods;
}
1
  • Thanks. I’ve added the user_contactmethods filter to my theme.
    – DKX
    Commented Jan 3, 2020 at 15:37

Your Answer

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

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