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:


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


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) {

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.

| improve this answer | |
  • I'm glad that helped. – berramou May 2 '19 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.