Parasolx

Professional in Drupal web development, theme designing, consultation and training

[Snippet] Load image alt and title in content

29 Jan 2014 - 08:34 pm

In Drupal 6, there is a module call ImageField Token which automatically define in markup. In Drupal 7, it can be done through theme preprocessing by using this code:

function MYTHEME_preprocess_image(&$vars) {
  // alt
  if (empty($vars['attributes']['alt'])) {
    $vars['attributes']['alt'] = DEFAULT_IMAGE_ALT;
  }

  // title
  if (empty($vars['attributes']['title'])) {
    $vars['attributes']['title'] = DEFAULT_IMAGE_TITLE;
  }
}
Kategori: 
Tags: 
snippets
drupal 7
image
theme
preprocessing