I am trying to add an attribute of "id="background" to the actual image tag.
<?php print render($content['field_bg_image']); ?>
I've looked up tons of articles and they are all concerned with hook_form_alter and this is not a form. This is simply just an image field, I just need an ID attribute on it with a value of background. I know I can use javascript but I want to use Drupal and not add any more javascript.
The image render is run through
theme_image_formatter()
which doesn't let you set attributes.You can get around this by building the image up manually:
That's untested so let me know if you have any problems
You could use a template for your cck field, in your case the name of this file could be
field--field-bg-image.tpl.php
and should be put inside your current theme folder, then you could add yourid
attribute like this:Have a look at field.tpl.php
If you wan't to set the
id
on the actualimg
tag you could do something along these lines in yourfield--field-bg-image.tpl.php
file:You may also checkout theme_image() and do like this: