Commit b004018c authored by Damien McKenna's avatar Damien McKenna
Browse files

Issue #3099168 by jedihe, DamienMcKenna, docans: Remove "title" meta tag,...

Issue #3099168 by jedihe, DamienMcKenna, docans: Remove "title" meta tag, leave the regular title tag.
parent 4ed7472e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ Metatag 8.x-1.x-dev, xxxx-xx-xx
  verification.
#3101288 by chr.fritsch: Fix namespace and imports.
#3090002 by DamienMcKenna: Rename migrate plugins to follow naming conventions.
#3099168 by jedihe, DamienMcKenna, docans: Remove "title" meta tag, leave the
  regular title tag.


Metatag 8.x-1.10, 2019-08-29
+17 −1
Original line number Diff line number Diff line
@@ -166,6 +166,18 @@ function metatag_page_attachments(array &$attachments) {
      ];
    }
  }

  // Remove the erroneous "title" meta tag as the page title has already been
  // overridden.
  // @see metatag_preprocess_html()
  if (!empty($attachments['#attached']['html_head'])) {
    foreach ($attachments['#attached']['html_head'] as $ctr => $data) {
      if (!empty($data[1]) && $data[1] == 'title') {
        unset($attachments['#attached']['html_head'][$ctr]);
        break;
      }
    }
  }
}

/**
@@ -414,7 +426,9 @@ function metatag_preprocess_html(&$variables) {
    return NULL;
  }

  // Load the page title.
  // Copy the "title" meta tag into the regular <title> tag. The redundant meta
  // tag will be removed elsewhere.
  // @see metatag_page_attachments()
  if (!empty($attachments['#attached']['html_head'])) {
    foreach ($attachments['#attached']['html_head'] as $attachment) {
      if (!empty($attachment[1]) && $attachment[1] == 'title') {
@@ -422,6 +436,8 @@ function metatag_preprocess_html(&$variables) {
        // the meta title.
        $variables['head_title'] = [];
        $variables['head_title']['title'] = html_entity_decode($attachment[0]['#attributes']['content'], ENT_QUOTES);

        // No need to do anything else after this.
        break;
      }
    }
+40 −8
Original line number Diff line number Diff line
@@ -71,8 +71,16 @@ class MetatagFrontpageTest extends BrowserTestBase {
    $this->drupalGet('<front>');
    foreach ($edit as $metatag => $metatag_value) {
      $xpath = $this->xpath("//meta[@name='" . $metatag . "']");
      if ($metatag == 'title') {
        $this->assertEqual(count($xpath), 0, 'Title meta tag not found.');
        $xpath = $this->xpath("//title");
        $this->assertEqual(count($xpath), 1, 'Head title tag found.');
        $value = $xpath[0]->getText();
      }
      else {
        $this->assertEqual(count($xpath), 1, 'Exactly one ' . $metatag . ' meta tag found.');
        $value = $xpath[0]->getAttribute('content');
      }
      $this->assertEqual($value, $metatag_value);
    }

@@ -81,8 +89,16 @@ class MetatagFrontpageTest extends BrowserTestBase {
    $this->drupalGet($node_path);
    foreach ($edit as $metatag => $metatag_value) {
      $xpath = $this->xpath("//meta[@name='" . $metatag . "']");
      if ($metatag == 'title') {
        $this->assertEqual(count($xpath), 0, 'Title meta tag not found.');
        $xpath = $this->xpath("//title");
        $this->assertEqual(count($xpath), 1, 'Head title tag found.');
        $value = $xpath[0]->getText();
      }
      else {
        $this->assertEqual(count($xpath), 1, 'Exactly one ' . $metatag . ' meta tag found.');
        $value = $xpath[0]->getAttribute('content');
      }
      $this->assertEqual($value, $metatag_value);
    }

@@ -130,8 +146,16 @@ class MetatagFrontpageTest extends BrowserTestBase {
    $this->drupalGet('<front>');
    foreach ($edit as $metatag => $metatag_value) {
      $xpath = $this->xpath("//meta[@name='" . $metatag . "']");
      if ($metatag == 'title') {
        $this->assertEqual(count($xpath), 0, 'Title meta tag not found.');
        $xpath = $this->xpath("//title");
        $this->assertEqual(count($xpath), 1, 'Head title tag found.');
        $value = $xpath[0]->getText();
      }
      else {
        $this->assertEqual(count($xpath), 1, 'Exactly one ' . $metatag . ' meta tag found.');
        $value = $xpath[0]->getAttribute('content');
      }
      $this->assertEqual($value, $metatag_value);
    }

@@ -160,8 +184,16 @@ class MetatagFrontpageTest extends BrowserTestBase {
    $this->assertResponse(200);
    foreach ($edit as $metatag => $metatag_value) {
      $xpath = $this->xpath("//meta[@name='" . $metatag . "']");
      if ($metatag == 'title') {
        $this->assertEqual(count($xpath), 0, 'Title meta tag not found.');
        $xpath = $this->xpath("//title");
        $this->assertEqual(count($xpath), 1, 'Head title tag found.');
        $value = $xpath[0]->getText();
      }
      else {
        $this->assertEqual(count($xpath), 1, 'Exactly one ' . $metatag . ' meta tag found.');
        $value = $xpath[0]->getAttribute('content');
      }
      $this->assertEqual($value, $metatag_value);
    }
  }