Friday, April 19, 2013

Remove the Joomla Meta Name Generator Tag

Plugin (Joomla 1.5, 1.6, 1.7 & 2.5)

By far the easiest way is to use the Joomla plugin ByeByeGenerator. Install the plugin, enable it, verify the meta tag is removed in the source code and you are done. Not only is the method the easiest, it will work for any version of Joomla. 1.5, 1.6, 1.7 & 2.5. This method is also persistent, so if you change your templates a lot or do any updates, this plugin will always work and never get overridden. But what if you are a purist?



Manually


Steps#A (Joomla 1.7)
In Joomla 1.7, the system automatically creates a META Generator tag that you might want to change or hide.

The default tag looks like this: <meta name="generator" content="Joomla! 1.7 - Open Source Content Management" />

There is no way within Joomla to change or remove this tag, so you have to put a little line of PHP in your template.
Edit your template and look for this line: <jdoc:include type="head" />

Just above that line, paste in the following: <?php $this->setMetaData('generator','my site'); ?>

The two lines together should look like this: <?php $this->setMetaData('generator','my site'); ?> <jdoc:include type="head" />

In the above code, substitute your custom generator tag value in place of the words my site.

Because this hack is in your template, you don’t have to worry about the next upgrade to Joomla overwriting hacked core files.

Ilustration with Joomla 1.7 default template Beez2 – Default

 
Editing the HTML of Beez2 – Default, you will see on line 36 is the opening HTML <head> tag, then on line 37 is <jdoc:include type=”head” />

We’re going to insert a new PHP command between line 36 and 37 — between the <head> tag and the <jdoc:include type=”head” />

Copy the following code:<?php $this->setMetaData('generator','my site'); ?>

Then paste this code into the Beez2 – Default template code between line 36 and 37. Your code should now look like this:

To customize this, you will replace your own value for the ‘my site’ value. In my case, I use my domain name.

Now, save the template and upload. Switch to your web browser, reload the page, and view the source.

Steps#B (Joomla 2.5)
The method to removing the meta name generator tag for Joomla varies between versions. On Joomla 2.5 you can simply add this code to your index.php file in your template.
JFactory::getDocument()->setGenerator('');

Put it just after the line //no direct access. This method will vary greatly on what template you are using and from what company, so I cannot get too detailed. For example YooThemes has a different template structure then RocketThemes. You will have to noodle around a bit yourself in order to do this. The main advantage of editing the template code instead of installing a plugin is less overhead. The fewer plugins you have, the faster your site will be, and queries add up fast.

Steps#C (Joomla 2.5)Add following line in the source code of the index.php of your template: $this->setMetaData('generator','');

Add it direct after the line: defined('_JEXEC') or die;

Steps#D (Joomla 2.5)
To remove the <meta http-equip> tag in Joomla 2.5.6 comment out (put 2 forward slashes at the beginning of) lines 72-102 in the file libraries/joomla/document/html/renderer/head.php (see below)
Also, remember to declare a character set elsewhere - such as in your .htaccess file .

// Generate META tags (needs to happen as early as possible in the head)
//foreach ($document->_metaTags as $type => $tag)
//{
//foreach ($tag as $name => $content)
//{
//if ($type == 'http-equiv')
//{
//$content .= '; charset=' . $document->getCharset();
//$buffer .= $tab . '<meta http-equiv="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
//}
//elseif ($type == 'standard' && !empty($content))
//{
//$buffer .= $tab . '<meta name="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
//}
//}
//}
// Don't add empty descriptions
//$documentDescription = $document->getDescription();
//if ($documentDescription)
//{
//$buffer .= $tab . '<meta name="description" content="' . htmlspecialchars($documentDescription) . '" />' . $lnEnd;
//}
// Don't add empty generators
//$generator = $document->getGenerator();
//if ($generator)
//{
//$buffer .= $tab . '<meta name="generator" content="' . htmlspecialchars($generator) . '" />' . $lnEnd;
//}
//$buffer .= $tab . '<title>' . htmlspecialchars($document->getTitle(), ENT_COMPAT, 'UTF-8') . '</title>' . $lnEnd;

Steps#E (Joomla 2.5)
Your Joomla site always comes with a default meta generator to show that your website is a Joomla site, and sometimes it will show its version as well. It is important to hide this for security measures if you do not want others to see your source code and know it is a Joomla site and what version it may be. It is good to be aware that the changes you make will be overwritten when upgrading your Joomla version.

1. Open your head.php file


Open your FTP program.
Navigate to this file: (root directory)/libraries/joomla/document/html/renderer/head.php
Open your head.php file with a Text Editor.

2. Navigate to the meta generator section of the PHP code



Look for the line of code that creates a function called getGenerator().

3. You can remove the line of code by commenting it out and your site will now show a meta name generator



Adding 2 slash lines in front of the code will prevent the website from rendering it as code. So it's basically removed, without removing it. It's always safe to do the commenting method so you can always revert back to previous changes.

4. Instead of commenting it, you can change the code


You can change this to any type of meta name you'd like. I changed my site to "author" with my name in the double quotes, removing everything else within the quotes first.

Congratulations! You now have full control of your header file, but remember you are able to edit most sections using your admin panel but it is good to know how to remove sections and where to find the actual file your header code is generated at

2 comments:

  1. When I go to my web site and hover over a menu, the sub menu does not show up. I have to click on that menu and then hover for the sub menu to show up. What's wrong?
    Domain Name Search

    ReplyDelete
  2. There is another easy alternative to DIY. The Joomla metadata suite plugin allows you to remove the generator tag or brand it.

    You can also remove the author tag, and add in additional metadata items for your social profiles including OpenGraph data.

    Download for free: https://webdesignandcompany.com/products/joomla-metadata-suite/

    Hope this helps.

    ReplyDelete