How do I remove the language_content_entity query from the canonical URL? Following the Translating content documentation we have setup our site to have Spanish, English, and Japanese. When we are adding, editing, deleting, and publishing pages in different languages we have no issues. However, when we view the canonical url, we find that the language_content_entity=en is added for English pages, for example. We are already adding the hreflang to each page so don't need this extra parameter in the canonical. 

For all English pages:

&lt;link rel="canonical" href="https://www.somedomain.net/some/path?language_content_entity=en"&gt;


For all Spanish pages: 

&lt;link rel="canonical" href="https://www.somedomain.net/some/path?language_content_entity=es"&gt; 


How can we remove the language_content_entity=en from the canonical url?
Just to illustrate once again what you are supposed to do with the first duplicate question's answer:

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

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

    if ((isset($head[1]) ? $head[1] : FALSE) == 'canonical_url') {

      $href = isset($head[0]['#attributes']['href']) ? $head[0]['#attributes']['href'] : FALSE;

      if ($href) {
        // Strip ?language_content_entity=en from the end of the URL if exists.
        $href = rtrim($href, '?language_content_entity=en');
        // Strip ?language_content_entity=es from the end of the URL if exists.
        $href = rtrim($href, '?language_content_entity=es');
        // Then set the new value.
        $attachments['#attached']['html_head'][$key][0]['#attributes']['href'] = $href;
      }
    }
  }
}