0

I am trying to remove specific HTTP response header from my site. The header looks like this:

Link: <https://example.com>; rel="canonical",<https://example.com>; rel="shortlink"

So far I have tried this simple code in my theme_html_head_alter:

header_remove("Link");

But that does not remove the header. Is there some specific Drupal way to deal with this, or am I using this code in wrong function? Or am I completely wrong with this?

Thank you in advance

0

You can remove it using hook_html_head_alter like the following:

/**
 * Implements hook_html_head_alter().
 */
function myTheme_html_head_alter(&$head_elements) {
  foreach ($head_elements as $key => $head_element) {
    if (strpos($key, 'drupal_add_html_head_link:shortlink') === 0) {
      unset($head_elements[$key]);
    }
  }
}

PS : the above code remove links with rel="shortlink" if you want to remove links with rel="canonical" just add another if and change shortlink by canonical.

  • I'm glad that helped. – berramou May 2 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.