You are here

function favicon_html_head_alter in Favicon 7.2

Implements hook_html_head_alter().

File

./favicon.module, line 33
Module file for favicon module.

Code

function favicon_html_head_alter(&$elements) {
  $file = favicon_get_favicon_file();
  if (empty($file) || $file->uri === DrupalFavicon::DEFAULT_URI) {
    return;
  }

  // Replace the existing shortcut icon link with the actual URL.
  $file->url = file_create_url($file->uri);
  if (!isset($elements['drupal_add_html_head_link:shortcut icon:' . $file->url])) {
    foreach ($elements as $key => $element) {
      if (strpos($key, 'drupal_add_html_head_link:shortcut icon:') === 0) {
        $new_key = 'drupal_add_html_head_link:shortcut icon:' . $file->url;
        $elements[$new_key] = $elements[$key];
        $elements[$new_key]['#attributes']['href'] = $file->url;
        $elements[$new_key]['#attributes']['type'] = $file->filemime;
        unset($elements[$key]);
      }
    }
  }
}