How to render alt and title texts of image file entities using a theme function Out of the box, image file entities have alt and title text fields attached, field_file_image_alt_text and field_file_image_title_text respectively, that provide the rendered image with an HTML alt and title text.

Today I feel like Mysite.com would be a great title for the images on my website, and I could easily programatically populate both text fields with Mysite.com upon upload of the image file. However, what if tommorrow I change my mind and instead of Mysite.com I want the alt and title text to be Welcome to Mysite.com? I would have to edit all file entities and modify both text fields for each.

Is there a way to render the alt and title text through a theming function so that I do not have to actually store the alt and title text within each file entity? I want to be able to modify the alt and title texts of all images by just modifying a single line of code.
The logic is pretty easy, you can just preprocess theme_image():

function MYTHEME_preprocess_image(&amp;$vars) {
  $vars['attributes']['alt'] = 'alt';
  $vars['attributes']['title'] = 'title';
}


If you're using any of the standard image display formatters they'll eventually be passed through theme_image() so that should work for all fields.

I'd strongly advise you consider not doing this though. The point of an alt tag is to describe the image to parties who can't interpret it in its original form (visually impaired people, robots, text only browsers, search engines, etc)

By setting the alt for every image to the same string, you're making your site quite inaccessible to those groups of visitors. And since Google and others assign a reasonable weight to alt text, you won't be doing your SEO any favours either.