Using 7.0-beta3 with default setting. Want to remove following line.

<meta name="Generator" content="Drupal 7 (http://drupal.org)" />

How can I remove it?

Comments

espirates’s picture

Wow just saw that meta tag, not sure why they are forcing users to have a generator tag. I'll be removing that for sure.

It's in includes/common.inc line 320-328

Here's what I did, not sure if it's the correct way but it worked.

removed these two lines by putting //

//      'name' => 'Generator',
//      'content' => 'Drupal ' . $version . ' (http://drupal.org)',

And then removed ['#attributes']['content'] from this line.

  $elements['system_meta_generator']['#attached']['drupal_add_http_header'][] = array('X-Generator', $elements['system_meta_generator']['#attributes']['content']);
madeinjapan’s picture

espirates, Thanks a lot. I hope above idea will help many Drupal lovers who do not want a generator tag in Druapl 7.

I like Drupal 6 because of it's simple (clean) coding. So, I was expecting more cleaned and small sized Drupal 7. But Drupal 7 beta is very very slow in test environment (WAMP).

espirates’s picture

Put inside your theme template.php, this way you don't have to mess with core files.

// remove a tag from the head for Drupal 7
function YOURTHEME_html_head_alter(&$head_elements) {
  unset($head_elements['system_meta_generator']);
}
akael’s picture

Thanks.

I think it is a really bad idea to be listing the generator like that without an easy way to turn it off.

I will be using this code in every theme I use for D7.

bellagio’s picture

Using template.php solution worked out great. Thank you!

madeinjapan’s picture

template.php solution is not working with every theme!!

kerios83’s picture

Their should be a easier way to remove this generator tag... I guess somewhere in configuration menu. And you need to put inside a clean template.php - if u have just make one:

<?php
// remove a tag from the head for Drupal 7
function YOURTHEME_html_head_alter(&$head_elements) {
  unset($head_elements['system_meta_generator']);
}

end of course this solution as is written above is not working with every theme...

SKAUGHT’s picture

perfect.

iNik’s picture

You can also do it through your Apache configuration. Just put this directive in your .htaccess file (or httpd.conf):

<IfModule mod_headers.c>
     Header unset X-Generator
     Header unset X-Drupal-Cache
     Header unset X-Powered-By
</IfModule>

I also generally remove X-Drupal-Cache, to avoid further announcements that this is Drupal, and also X-Powered-By so that people don't look for PHP vulnerabilities. If you have access to your own php.ini file, you can do this globally by adding the setting:

expose_php = Off

If you want to get even fancier, you can hide a lot of apache information with these other options:

ServerSignature Off
ServerTokens Prod

That will ensure that you don't broadcast your version of Apache. None of these make you super secure, but they do avoid scripts that go through headers looking for vulnerable versions of Apache, Drupal or whatever.

redben’s picture

Best answer. Thanks

csmcreative’s picture

Much appreciated.

meaton’s picture

This answer worked great. Thanks!

dullarobin’s picture

@iNik, it's a really helpful post. Saves me lot of time.
Thanks

mcfilms’s picture

Can someone share with me why it is such a bad idea to include the meta tag for generator and attribute it to Drupal?

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

espirates’s picture

A typical reason might be to not let spambots know what cms you are using.

Another reason might be simply, because we just don't want it. I think certain things should be left up to the user to decide if they want to add or not. Personally I prefer as clean a source code as possible and don't want it.

Another item that should be removed is Drupal.settings or be changed to site.settings. Some stuff should be taken out, it's not necessary to have it there. There's so much gunk printed, very messy. I like modx cms for that reason, it keeps the code clean and also separates it from the design.

One of these days I'm going to gut it all out.

Can someone share with me why it is such a bad idea to include the meta tag for generator and attribute it to Drupal?

oeroek’s picture

When looking for ways to remove the meta generator I came by this discussion about adding the meta generator. The developers choose not to include a setting since it would add complexity to the user interface. Since it is easy to delete the meta generator it becomes a choice for themers to delete it.

http://drupal.org/node/275092

madeinjapan’s picture

There is a module. Remove Generator META tag.

http://drupal.org/project/remove_generator

exterm’s picture

How do i remove from Blog post

I tried all the solution but not able remove from blog post when try to create new blog i see the same
"meta name="generator" content="Drupal 7 (http://drupal.org)"

Pls help..

pwhiteside’s picture

You could try the Metatag Module,

http://drupal.org/project/metatag

Leaving it blank makes the metatag dissapear.
This should also remove it from other pages.

rojosnow’s picture

I think you are looking to unset the metatag_generator based upon dpm.

function YOURTHEME_html_head_alter(&$head_elements) {
  dpm($head_elements);
  unset($head_elements['metatag_generator']);
}

This worked for me...system_meta_generator did not.

iAugur’s picture

You can do this in the template.php a module

<?php
function YOUR_MODULE_OR_THEME_html_head_alter(&$head_elements) {
  unset($head_elements['system_meta_generator']);
}
?>

The example in the previous comment includes a call to dpm() which requires the devel module and will error if you don't have that enabled.

George Boobyer
www.blue-bag.com

phponwebsites’s picture

After removed generator meta tags, always it displays generator meta. This is only works after clear cache and also for few minutes. Then it has been showed. What is the exact solution for remove generator meta tag in Drupal?

FiNeX’s picture

Did you enabled metatag module? In that case you can configure it from the metatag settings page.

albertguedes’s picture

csmcreative’s picture

Worked great.

Killing Hours’s picture

I understand that this particular question is regarding D7, however, I searched for the same technique for D8 and came up short.

Here is the D8 way to accomplish this for those who find themselves looking for the answer to no avail.

In the "THEMENAME.theme" file of in the base of your theme put this:

/**
 * Removes the Generator Meta Tag from Drupal 8
 */
function THEME_page_attachments_alter(array &$attachments) {
    unset($attachments['#attached']['html_head'][1][0]);
}

Obviously change THEME to match your theme name.

* D8 may have some proper way of removing it but I'm barely 3 months into learning Drupal and only on version 8.
** Please be gentle if I've not place this in a correct place as this is my first time posting on here.

Hopefully this helps some future reader.

fhdrupal’s picture

Come-on guys what so bad and difficult about it? It can easily be removed by the following settings, no need of any custom module or script.
Go Config > metatags > global edit > advance > Generator.
Just empty text in generator input box and the generator meta tag will completely disappear from the header, because once the string is empty the Drupal will not output the whole meta tag at all.

krutibhakta’s picture

Use following function in your theme/template.php file


function yourtheme_html_head_alter(&$head_elements) {
  unset($head_elements['system_meta_generator']);
}

It will not generate
in web page.

TechNikh’s picture

For me 'system_meta_generator' didn't work. "metatag_generator_0" worked after I printed $head_elements in watchdog

watchdog("debug", "in payeezy_lite_html_head_alter ".print_r($head_elements, TRUE));
/**
 * Implements hook_html_head_alter().
 */
function my-theme-name_html_head_alter(&$head_elements) {
  watchdog("debug", "in html_head_alter ".print_r($head_elements, TRUE));
  unset($head_elements['metatag_generator_0']);
}

Cheers,
TechNikh

In 30 seconds set up Automated Visual testing of your website. Zero coding. https://drupal.org/project/drulenium
Ever dreamed of styling your view, We have a solution for you. https://drupal.org/project/views_stylizer

rmcdahal’s picture

function theme_name_page_attachments_alter(array &$attachments) {
foreach ($attachments['#attached']['html_head'] as $key => $attachment) {
if ($attachment[1] == 'system_meta_generator') {
 unset($attachments['#attached']['html_head'][$key]);
 }
   }
 }
izmeez’s picture

Thanks all for this useful discussion on removing the meta generator tag.

The suggestion to also unset X-Drupal-Cache header leaves me a bit confused. Isn't this needed for drupal cache to work and for vanish to work?

sprite’s picture

If you use the metatag module you can overwrite the generator metatag with whatever you want very easily, as you add in all the other metatags you'll want to maximize your SEO.

Go the the the metatag module settings to got - global metatags - advanced tags. The generator tag is there.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

rmcdahal’s picture

Metatag Module Dosen't remove Generater tags for drupal 8.

sprite’s picture

Surely the D8 version of the metatag module will catch up to the D7 version, eventually, just as so many other aspects of D8 are far behind the current overall status of D7.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...