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.
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
<?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' => 'markup',
'#markup' => $result,
'#attached' => [
'html_head' => [
[
[
'#tag' => 'meta',
'#attributes' => [
'property' => 'og:description',
'content' => $result->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.