How to control metatag module's tags from a page callback?
There's a hook for that. Here's my implementation.
&lt;?php

function mymodule_some_page_callback() {
  global $metatagOverrides;
  // ... generate your page ...

  $metatagOverrides = [
    'og:image' =&gt; 'https://example.org/the-image.jpg',
    'og:description' =&gt; 'Some description',
    ...
  ];

  return $thePage;
}

function mymodule_metatag_metatags_view_alter(&amp;$output, $instance, $options) {
if (!empty($metatagOverrides)) {
  foreach ($metatagOverrides as $tagname =&gt; $value) {
    if (array_key_exists($tagname, $output)) {
      $output[$tagname][&quot;#attached&quot;][&quot;drupal_add_html_head&quot;][0][0][&quot;#value&quot;] = $value;
    }
    else {
      $output[$tagname] = [
        '#attached' =&gt; [
          'drupal_add_html_head' =&gt; [
            [
              [
                '#theme' =&gt; 'metatag_property',
                '#tag' =&gt; 'meta',
                '#id' =&gt; &quot;{$tagname}_0&quot;,
                '#name' =&gt; $tagname,
                '#value' =&gt; $value,
                '#weight' =&gt; 100,
              ],
              &quot;{$tagname}_0&quot;,
            ]
          ]
        ]
      ];
    }
  }
}