Create a theme function for form fields I need to theme certain form fields on the user profile form page differently from other fields, for which I am trying to create a theme function that outputs html its own way, not using theme_form_element(). The reason for defining a new theme function alternative to theme_form_element() is because the html output is dramatically different. 

This is my code:

function mymodule_theme() {
  return array(
    'profile_form_element' =&gt; array(
      'variables' =&gt; array(
        'element' =&gt; NULL,
      ),
    ),
  );
}

function mymodule_form_user_profile_form_alter(&amp;$form, &amp;$form_state) {
    $form['field_user_first_name']['#theme'] = 'profile_form_element';
    dpm($form['field_user_first_name']);
}

function theme_profile_form_element(&amp;$variables) {
  $element = &amp;$variables['element'];
  // my html processing would start here...
}


...but the theme function has NULL for $variables['element']. What am I doing wrong? I am attaching the structure of my form field (field_user_first_name), which was created through the UI at configuration > people > account settings > manage fields.
I think one of your problem is with this:

$element = &amp;$variables['element'];


I don't think you can assign a reference to an array element (the &amp;), so try changing it to:

$element = $variables['element'];


and I don't see a 'element' element, so unless I'm blind you're trying to access an element that isn't there, so it will always return NULL;