<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Christian Schenk&#187; meta</title>
	<atom:link href="http://www.christianschenk.org/blog/tag/meta/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christianschenk.org</link>
	<description>Writing about my experiences with technology and all different kinds of projects and experiments</description>
	<lastBuildDate>Sun, 29 Aug 2010 09:08:16 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Removing the WordPress Generator meta tag completely</title>
		<link>http://www.christianschenk.org/blog/removing-wordpress-generator-meta-tag-completely/</link>
		<comments>http://www.christianschenk.org/blog/removing-wordpress-generator-meta-tag-completely/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 21:25:36 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/?p=358</guid>
		<description><![CDATA[Shows you how to remove the generator meta tag completely that's being added by WordPress' core after a fresh installation]]></description>
			<content:encoded><![CDATA[<p>WordPress adds a <em>generator</em> tag at various locations. Basically that&#8217;s a good idea because it provides a means to check out the different versions of WordPress that are actively being used in the blogosphere.</p>
<p><span id="more-358"></span></p>
<p>I&#8217;ve found the generator meta tag in my fresh installation of WordPress 2.7 here, there and everywhere:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* In the HTML header */</span>
<span style="color: #339933;">&lt;</span>meta name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;generator&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;WordPress 2.7&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* In the RSS feed */</span>
<span style="color: #339933;">&lt;</span>generator<span style="color: #339933;">&gt;</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//wordpress.org/?v=2.7&lt;/generator&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* In the Atom feed */</span>
<span style="color: #339933;">&lt;</span>generator uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://wordpress.org/&quot;</span>
 version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;2.7&quot;</span><span style="color: #339933;">&gt;</span>WordPress<span style="color: #339933;">&lt;/</span>generator<span style="color: #339933;">&gt;</span></pre></div></div>

<p>And the <a href="http://trac.wordpress.org/browser/tags/2.7/wp-includes/general-template.php#L1872">code suggests</a> that there&#8217;re even more places where this tag might show up.</p>
<h2>How to remove it completely</h2>
<p>If you&#8217;re doing some <a href="http://codex.wordpress.org/Hardening_WordPress#Security_through_obscurity">security through obscurity</a> you might have <a href="http://www.google.com/search?q=remove+wordpress+meta+generator">googled</a> a little bit and found the solutions that use the following piece of PHP code just unsatisfactory:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">remove_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wp_generator'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So let&#8217;s remove it completely like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> rm_generator_filter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_generator'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rm_generator_filter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This will remove the tag everywhere: from the HTML, the RSS and the Atom feed, et cetera.</p>
<h3>WordPress&#8217; world of possibilities&#8230;</h3>
<p>Now I&#8217;d like to present another solution that might make sense: What about removing the generator tag almost everywhere <strong>but</strong> not in case of RDF content? Since RDF is widely used as a format for data mining applications why not show the information to these web robots? You could do this like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> rm_generator_filter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'add_filter'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$types</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'xhtml'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'atom'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rss2'</span><span style="color: #339933;">,</span>
                 <span style="color: #666666; font-style: italic;">/*'rdf',*/</span> <span style="color: #0000ff;">'comment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'export'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$types</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span>
    add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'get_the_generator_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rm_generator_filter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>What it does is adding a filter for every <code>type</code> but <em>RDF</em> returning just and empty string for the generator meta tag.</p>
<p>Although this doesn&#8217;t make much sense from the standpoint of security through obscurity because making the information available in just one place would compromise your <em>security</em> anyway, I just wanted to show that WordPress is flexible enough to do something like this.</p>
<h2>Download</h2>
<p>You can download the above code packaged in a plugin <a href="http://data.christianschenk.org/removing-wordpress-generator-meta-tag-completely/remove-generator-meta-tag.zip">here</a>. Have a look at the code and checkout the <code>define</code> in line 30: set it to true or false whether you&#8217;d like to remove the tag completely or not; the default is to remove it just everywhere.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/removing-wordpress-generator-meta-tag-completely/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
