How to set rel="alternate" hreflang="x"? I am trying to set my hreflang links with this code:

$langcode= $GLOBALS['language']-&gt; language;
//Get enabled languages
$langcode= array_pop(language_list('enabled'));
unset ($languages[$langcode-&gt;language]);

// Get path
$path1 = drupal_is_front_page() ? '&lt;front&gt;' : $_GET['q'];
//Get Urls 
$links = array();
foreach ($languages as $lang) {
  $links[$lang-&gt;language] = array(
    'href'=&gt; $path1,
    'language'=&gt;lang,
    'absolute'=&gt; TRUE,
  );
}
drupal_alter('translation_link', $links, $path1);

//Set head tags
foreach($links as $link) {
  drupal_set_html_head('&lt;link rel="alternate" hreflang="'.   $link['language']-&gt;language .'" href="'. url($link['href'], $link) .'" /&gt;');
}
//Update head
$vars['head'] = drupal_get_html_head();


with no luck.

While researching I have found this module Internationalization contributions
but it doesn't do anything. Or I don't know how to use it.
You tagged your question as Drupal 7 so I'm guessing the only problem is that you're using drupal_set_html_head() which doesn't exist in Drupal 7.

It's been replaced with drupal_add_html_head(), which you can use like so:

$element = array(
  '#tag' =&gt; 'link', 
  '#attributes' =&gt; array( 
    'hreflang' =&gt; 'some_language', 
    'rel' =&gt; 'alternate',
  ),
);
drupal_add_html_head($element, 'mymodule');