Programmatically add custom meta description via metatag module I'm trying to add a custom meta tag description for a custom module using the metatag module.

I tried this without success:

function mycustommodule_metatag_metatags_view_alter(&amp;$output, $instance) {
  if ($instance == 'mycustom:entity') {
    $output['description']['#attached']['drupal_add_html_head'][0] = array(
      array(
        '#tag' =&gt; 'meta',
        '#name' =&gt; 'desription',
        '#value' =&gt; $my_custom_description,
      ),
      'description',
    );
  }
}
Instead of directly altering the metatag, you might want to look into creating a custom token: As described in this article

This will give you more freedom and flexibility. Then you can just use that custom token in the backend of metatags and configure it for content types that you like.

/admin/config/search/metatags


If you however, still prefer to use the hook in the op, don't forget that those are cached, you will need to clear all caches before it might appear.