Metatag: How to programmaticaly set a node's canonical URL I am using the metatag module for defining several meta tags. As a default value, canonical tags use '[current-page:url:absolute]'.
Now I want to create a module that sets the value of the canonical tag to some other url.

Setting $node['metatags']['und']['canonical']['value'] to another string doesn't seem to work. Unfortunately, I also can't use an entity_wrapper, since metatag doesn't define information for its custom fields, which is needed by entity_wrapper.

Is there something else I could do?
look into the hook: metatag_metatags_view_alter().

/**
 * Implements metatag_metatags_view_alter()
 */
function mymodule_metatag_metatags_view_alter(&amp;$output, $instance) {
  // Add Custom logic to overwrite the canonical tag here.
  $canonical = 'http://www.mysourceurl.com';

  // Alter canonical tag.
  $output['canonical']['#attached']['drupal_add_html_head'][0][0]['#value'] = $canonical;
}