Undefined index: und in mytheme_preprocess_page() I created a custom image field for a banner in one of my content type. I wish to display this banner in the page.tpl.php instead of node template. Here's my code in template.php:

function mytheme_preprocess_page(&amp;$vars, $hook) {

     $vars['banner'] = ''; 
    if (!empty($vars['node'])) {
        $node = $vars['node'];

        if (isset($node-&gt;field_banner)) {
                // Render the image as a variable in the page template
           $vars['banner'] = theme_image_style(array('path' =&gt; $node-&gt;field_banner['und']['0']['uri'], 'style_name' =&gt; 'mybannerstyle', 'height' =&gt; '200', 'width' =&gt; '700'));
        } 
    }   


.....

and in the page.tpl.php, i coded:

    &lt;?php if(!empty($banner)){print $banner;} ?&gt; 


. This work perfectly in the node that has banner uploaded. But for nodes which have no banner, the following undefined messaged turn up:

Notice: Undefined index: und in mytheme_preprocess_page() (line 33 of /home/xxxxx/themes/mytheme/template.php). 

I wonder how to solve this. Please advise. Thanks.
For a field, $entity-&gt;$field_name['und'] is not always defined. Instead of the code you are using, you should use the following code.

if (isset($node-&gt;field_banner)) {
  // Render the image as a variable in the page template.
  $field = field_get_items('node', $node, 'field_banner');
  $vars['banner'] = theme_image_style(array('path' =&gt; $field[0]['uri'], 'style_name' =&gt; 'mybannerstyle', 'height' =&gt; '200', 'width' =&gt; '700'));
} 


I would also consider using field_view_value(), instead of fields_get_items(), but the first function doesn't allow to customize the output, if not through the $display parameter. (See field_view_field() for a description of that parameter.)

field_get_items() and field_view_value() get the language ID from field_get_name(), which returns the correct value for the language to use for the field.