There are already metatags created for this route.

Created on 8 December 2022, about 2 years ago
Updated 15 July 2024, 6 months ago

Problem/Motivation

When I try to add a new custom route of a new form I get the following:
"There are already metatags created for this route."

Steps to reproduce

Activate
Metatag Custom Routes (Paths)

- Create first form with webform module and add meta tag for custom path eg webform path /contact us

- Create second form and add meta tag for the custom route for the second form, for example /custom-contact there you will see the following error "There are already metatags created for this route." even though it's a new route, show error.

🐛 Bug report
Status

Active

Version

1.22

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇳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 6 months ago
  • 🇮🇳India vinai_katiyar 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 6 months ago
  • 🇺🇸United States DamienMcKenna NH, USA
  • 🇺🇸United States olarin

    FYI, I had a client encounter this same issue and get confused by a page display on a View with a contextual filter in the URL (to the end user it looks like multiple distinct pages, one for each valid value of the contextual filter, whereas it's obviously just one route underneath). It might be nice if there was a way to at least describe the problem more clearly to non-technical users in the error message, but I'm not sure what that would look like.

Production build 0.71.5 2024