How do I remove the language_content_entity query 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;
      }
    }
  }
}