Make a field theme function work on empty fields I am using a field theme function in my template.php file to override a field.

Everything works fine, but the function only seems to run if my field has content. If my field is empty, it does not run. How can I get the function to run all the time?

Here is the code I am using. The function checks a value in theme_settings.php and then alters the output of the field accordingly. 

function THEMENAME_field__field_call_to_action_button(&amp;$variables) {
 // kpr($variables);

    //Load the value of CTA to determin which text to use
    $field_cta_option = field_get_items('node', $variables['element']['#object'], 'field_call_to_action_setting');
        $cta_option = $field_cta_option[0]['value'];


    //Assign theme/node settings to variables for easy access   
    $cta_link_main      = theme_get_setting('cta_main_node');
    $cta_link_secondary = theme_get_setting('cta_secondary_node');
    $cta_link_custom    = theme_get_setting('cta_main_node');
    $cta_text_main      = theme_get_setting('cta_main_button_text');
    $cta_text_secondary = theme_get_setting('cta_secondary_button_text');
    $cta_text_custom    = $variables['#items'][0]['value'];
    switch ($cta_option) {
        case 'cta_main':
            return ctabutton($cta_link_main, $cta_text_main);
            break;
        case 'cta_secondary':
            return ctabutton($cta_link_secondary, $cta_text_secondary);
            break;
        case 'cta_custom':
            return ctabutton($cta_link_custom, $cta_text_custom);
            break;
        case 'cta_none':
            return "";
            break;
    }
}
You may want to change the way you are theming the information, for example by overriding node.tpl.php, but if you really want the field function to be run even when the field is empty, you can do it by modifying the node before it gets displayed:

function THEMENAME_preprocess_node(&amp;$variables) {
  if($variables['type'] == 'mynodetype' &amp;&amp; !isset($variables['content']['FIELD'])) {
      $variables['content']['body'] = array(
      '#theme' =&gt; 'field', 
      '#field_type' =&gt; 'FIELDTYPE', 
      '#field_name' =&gt; 'FIELDNAME', 
      '#items' =&gt; array(), 
      '#bundle' =&gt; 'mynodetype', 
      '#label_display' =&gt; 'hidden', 
      '#entity_type' =&gt; 'node');
  }
}


This will make sure the field is passed to your theme field function, even if it is empty.

To get the values to use for FIELDNAME and FIELDTYPE you can print out the contents of $variables['content'] on a page where the field is not empty.

Again, it might be better to override the theme of the entire node in this situation.