How to add field above password section in profile page

let’s continue the saga then 🙂

Yesterday I released a new version of my plugin that deals with customizing the Profile page, among other things. So the subject interests me quite a bit.

I managed to move the whole block of custom usermeta using this answer, but haven’t found much room for maneuvering.. Meaning: the usermeta goes in the beginning instead of the end.

Problem is that the profile page doesn’t have blocks of html with an assigned ID that would help positioning where we want. I tried to play with jQuery("#your-profile table:nth-child(2)") to no avail…

Anyway, this is the code:

<?php
/*
 #your-profile -> form that holds all profile options (WP default)
 #my-custom-profile -> div wrapping all you custom usermeta html block
*/
function se49859_script_enqueuer(){
    global $current_screen;
    if ($current_screen->id == 'profile') {
        echo '<script type="text/javascript">
        jQuery(document).ready( function($) {
            $("#your-profile").before($("#my-custom-profile"));
        });
        </script>';
    }
}
add_action('admin_head', 'se49859_script_enqueuer');