Drupal7: How to add the alt and title attribute to an image by code I am using the file_create_url() function to create the URL for images.
The code is:

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


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?

Thanks.

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

&lt;?php
$image = field_get_items('node', $node, 'field_history_image');
$output = field_view_value('node', $node, 'field_history_image', $image[0]);
print render($output);
?&gt;


OR

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