3

I try to remove shortlink and generator link from my site.

<meta name="generator" content="Drupal 7 (http://drupal.org)">
<link rel="shortlink" href="http://landberg.at/nl/node/109">

I used below code in template.php but when i look in my source code its still there?

function landberg_html_head_alter(&$head_elements) {
    unset($head_elements['system_meta_generator']);
    foreach ($head_elements as $key => $element) {
        if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'canonical') {
          unset($head_elements[$key]);
        }
        if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'shortlink') {
          unset($head_elements[$key]);
        }
    }
}

What is best way to remove this?

  • Your code is correct. Make sure that you cleared the cache. – Aram Boyajyan Feb 25 '16 at 12:24
  • @Aram Boyajyan i already cleared cash but the code is still showing up? – meez Feb 25 '16 at 13:38
  • Strange; I checked the code and it works fine. Is the name of your theme exactly landberg? Add there a watchdog entry (e.g. watchdog('debug', 'hook_html_head_alter() called from the theme');) to make sure it is executed. – Aram Boyajyan Feb 25 '16 at 13:58
  • it was because it was overwritten by Meta tag module... Thanks – meez Feb 25 '16 at 14:14
  • Good catch - glad you managed to resolve it! – Aram Boyajyan Feb 25 '16 at 14:15
4

Above code is good but it didn't work because it was overwritten by Meta tag module. I adjust some settings in Configuration » Search and metadata and now generator tag and shortlink is gone.

| improve this answer | |
  • That is a proper solution. Sadly it needs to be done on all Metatag elements. – kwoxer Jun 4 '18 at 15:08
  • You could also simply add unset($head_elements['metatag_shortlink']); to your above snippet. Although I don't like how this then invalidates the admin UI. As no matter what anyone will put in these fields on the Metatag settings form, the values will be overwritten by that line. – leymannx Nov 23 '18 at 22:15

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.