How can I disable meta tags provided by the Metatag module for a custom route? I have created a custom module for displaying the players information. Module will create dynamic pages and each page will display players stats. With the help of the following links, I was able to add meta tags to my module. 


How to add meta tag in head
Adding meta tags


Since each of the page generated by my module for separate meta information, I was not able to use page_attachement_hooks. Using the above links, I was able to add meta information in my controller itself. 

But, I am using Meta tag drupal module for generating meta information for other pages. Now I am getting multiple meta tags with same property name. Global configurations of meta tag module is displaying along with my meta tags. 

I read in some blog that if multiple meta tags found with same property, few crawlers will ignore them. How do I keep only my meta tags?

I saw this post which says how to override the meta tags. But there the code has to be placed in the module and it will be static. I wanted dynamic meta tags for each page. How will I achieve it?

Here is my code.

PlayerController.php

&lt;?php

namespace Drupal\player\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal;

class PlayerController extends ControllerBase {

  public function content($player) {
    $result = [];
    /* --------------
     code logic here 
    ------------------ */
    return [
      '#type' =&gt; 'markup',
      '#markup' =&gt; $result,
      '#attached' =&gt; [
        'html_head' =&gt; [
        [
         [
          '#tag' =&gt; 'meta',
          '#attributes' =&gt; [
            'property' =&gt; 'og:description',
            'content' =&gt; $result-&gt;player_details,
          ],
        ],
        'player',
      ],
    ],
  ],
    ];
  }

}


For reference, I am adding link to my old question regarding how to add meta tags in dynamic module. It have more codes in case you need.
Edit – @AlfredArmstrong pointed me to the hooks provided by the Metatag module itself. And there's hook_metatags_alter() you can implement to completely disable all meta tags added by the Metatag module. Much shorter than my original answer.

/**
 * Implements hook_metatags_alter().
 */
function MYMODULE_metatags_alter(array &amp;$metatags, array &amp;$context) {

  // Exclude meta tags on 'player' route.
  if (\Drupal::routeMatch()-&gt;getRouteName() === 'player') {
    $metatags = NULL;
  }
}




Original answer – I've had similar problems before. You can override or unset meta tags added by the Metatag module implementing hook_page_attachments_alter() like in the following example.

/**
 * Implements hook_page_attachments_alter().
 */
function MYMODULE_page_attachments_alter(array &amp;$attachments) {

  // Check for the route you want to override.
  if (\Drupal::routeMatch()-&gt;getRouteName() === 'player') {

    // An array of tags you want to unset.
    $unset = [
      'description' =&gt; 1,
      'abstract' =&gt; 1,
      'keywords' =&gt; 1,
    ];

    $meta_tags = $attachments['#attached']['html_head'];
    foreach ($meta_tags as $key =&gt; $meta_tag) {

      // And now unset them.
      if (isset($unset[$meta_tag[1]])) {

        unset($attachments['#attached']['html_head'][$key]);
      }
    }
  }
}