I am using the file_create_url() function to create the URL for images. The code is:

<img src="<?php echo file_create_url($node->field_history_image['und'][0]['uri']); ?>">

But I just noticed that the alt and title attributes are not added to the HTML output, eventhough I added them for the image in the admin.

How would I change the above code, so that it adds the alt and title attributes if they are filled in the Admin interface. Or what other function should I use?



2 Answers 2


Since you are rendering a field , you can use below code

$image = field_get_items('node', $node, 'field_history_image');
$output = field_view_value('node', $node, 'field_history_image', $image[0]);
print render($output);


$view = field_view_field('node', $node, 'field_history_image');
print render($view);

Here is my answer to my own question:

 <?php print render ($content['field_history_image']); ?>

The above code, prints the image (the URL and the alt and title attributes if they exist). It does exactly what I wanted.

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.