- 🇨🇳China hongqing
I have the same issue with Metatag 2.0.0 and Drupal 10.3.0 when add tags to custom route.
- Status changed to Needs review
about 2 months ago 6:17am 18 July 2024 - 🇮🇳India vinaik Delhi NCR
Hi @nelo_drup, @hongqing,
I set the meta tags for a custom route of a webform and got a success message "Created metatags for the path: /form/custom-contact. Internal route: entity.webform.canonical.". but when I tried to set meta tags for second webform using their custom route then got the error message "There are already metatags created for this route".
The error "There are already metatags created for this route" typically occurs because the Metatag module in Drupal considers the internal route of the webform rather than the URL alias.
So the internal route for viewing a webform is typically entity.webform.canonical and the path is usually /webform/{webform_id}.
Kindly refer to the attached screenshot for reference.
You can use the below custom logic in custom module or theme hook to set meta tags for custom route of the webforms -
if (\Drupal::routeMatch()->getRouteName() == 'entity.webform.canonical') { $alias = \Drupal::service('path_alias.manager')->getAliasByPath(\Drupal::service('path.current')->getPath()); if ($alias == '/contact-us') { // Add meta tags for /contact-us $variables['#attached']['html_head'][] = [ [ '#tag' => 'meta', '#attributes' => [ 'name' => 'description', 'content' => 'Contact us form description', ], ], ]; } elseif ($alias == '/custom-contact') { // Add meta tags for /custom-contact $variables['#attached']['html_head'][] = [ [ '#tag' => 'meta', '#attributes' => [ 'name' => 'description', 'content' => 'Custom Contact us form description', ], ], ]; } }
- Status changed to Active
about 2 months ago 3:18pm 18 July 2024