I have a custom field in d7 and I output it as

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

The problem is it wraps around a whole load of stuff. How can I get in and edit this html?

I suspect somewhere in the field templates or using the api. I can live with the bloated html if I could get rid of the title on the a tag (title="Sample 1")

<span class="image-wrapper"><a title="Sample 1" href="#1" rel="history" class="advance-link">
                    <div class="field field-name-field-product-image field-type-image field-label-hidden"><div class="field-items"><div class="field-item even"><img typeof="foaf:Image" src="http://extranet.shy-uk.com/sites/extranet.shy-uk.com/files/look-detail_0.jpg" width="620" height="320" alt=""></div></div></div></a></span>

2 Answers 2


inspect the field with dpm($node); or dpm($content['field_product_image'] you will see the array structure which should be something like:


to actually render the uri (something like public://filename.extension) you will need to to this:

$filename = $node->field_product_image['und'][0]['filename'];
$image_uri = file_build_uri($filename);
// url
$url = image_style_url('my style', $image_uri);
// html
print theme('image_style', array('style_name' => 'my style', 'path' => $image_uri));

update (shorter, one needless function call removed):

// url
$url = image_style_url('my style', $node->field_product_image['und'][0]['uri']);
// html
print theme('image_style', array('style_name' => 'my style', 'path' => $image_uri));

You can override field.tpl.php and its derivatives if you want to code it manually.

Or the Fences module might do the trick:

Fences is a an easy-to-use tool to specify an HTML element for each field. This element choice will propagate everywhere the field is used, such as teasers, RSS feeds and Views. You don't have to keep re-configuring the same HTML element over and over again every time you display the field.

It lets you control the base markup for each field through the UI - a must have for any project these days in my opinion :)


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.