22

I have these tags:

<meta name="generator" content="Woo Framework Version 3.1.1" />
<meta name="generator" content="WordPress 3.5" />
<meta name="generator" content="Canvas 3.0" />

I understand to remove the WordPress version tag I add:

remove_action( 'wp_head', 'wp_generator' ); // goes into functions.php

But how do I remove the themes meta tags?

10 Answers 10

32

If you are trying only to remove the meta="generator" add this line to your functions.php.

remove_action( 'wp_head', 'wp_generator' );
1
  • 3
    That only removes the line with the WordPress version. Commented Sep 12, 2014 at 12:10
23

Was looking for a solution for removing Layer Slider meta generator, didn't find much help on any of the handful of websites I looked at, they are all sharing the same info, which only pertains to either WordPress generator or popular plugins like WooCommerce.

The problem here is that every plugin is going to have it's own hook names and naming conventions, so to learn or know them all will be nearly impossible. The easiest way I think is plain PHP with preg_replace.

Working code that has been tested in WordPress 6.5. Inside functions.php of your theme drop in this code and it should work.

//Remove All Meta Generators
ini_set('output_buffering', 'on'); // turns on output_buffering
function remove_meta_generators($html) {
    $pattern = '/<meta name(.*)"generator"[^>]*>/i';
    $html = preg_replace($pattern, '', $html);
    return $html;
}
function clean_meta_generators($html) {
    ob_start('remove_meta_generators');
}
add_action('template_redirect', 'clean_meta_generators', 100);
add_action('wp_footer', function(){ ob_end_flush(); }, 100);

I am using regular expression to capture the meta tag. It covers whether they put spaces in between the equals sign or not. Using ob_start to cover the whole document. So we add the preg_replace starting at the header all the way to the footer. See how ob_start works in the PHP Manual, also there are times WordPress codex does states it should be using ob_start.

If you find this useful please add a thumbs up so the next person looking can land on a working solution that covers all meta generators. I feel it's bad security for these plugin and platform developers to put meta generator version numbers in the code. Especially with evolving vulnerabilities being discovered all the time.

Ive also added a plugin that does this exact thing on the WordPress repository.

Remove Meta Generators

7
  • This will not necessarily work on all themes. I've found that kjy112 's answer below is more likely to be the correct answer. (I tested on WP 4.9.6 with various themes, but without WooCommerce.) Commented Jul 1, 2018 at 1:33
  • This should work on all themes. All themes have a header and a footer and the code provided just uses plain php regular expression to strip out the meta generator tags. If you are having an issue with the code it could be a server issue with ob_start configurations. What errors are you getting when you say it "will not necessarily work on all themes"?
    – webbernaut
    Commented Jul 2, 2018 at 17:30
  • There are no errors; it just didn't work on a couple of my test sites. I found that the answer from @kjy112 worked in all of my test sites. Commented Jul 2, 2018 at 19:32
  • Do you have debug enabled? Sometimes there are error messages but are being suppressed. Also curious are these custom themes or can you send a link to one of them. This code again is just using pure PHP for stripping out meta generator tags, it should work on pretty much all themes unless there is a server issue.
    – webbernaut
    Commented Jul 3, 2018 at 19:54
  • 1
    @Nathan, thanks for the feedback. Ive edit the regex in the original post, basically tightened it that should fix your edge case of it spilling over into a tag that is on the same line. And this would also fix a hypothetical minified html case as well. Pushing the update to the official WordPress Plugin as well.
    – webbernaut
    Commented Apr 4 at 21:38
6

I recently ran into this issue, and had to remove the meta tags for security and spam reasons for a client. I was able to remove Wordpress's meta generator but the theme uses woo framework so using

remove_action('wp_head', 'wp_generator');

Is not sufficient. To remove

<meta name="generator" content="Woo Framework Version x.x.x" />

and anything any meta generator tags that your theme generates simply add this line to the end of your template's functions.php

// remove the unwanted <meta> links
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'woo_version'); 

This worked for me on Woo Framework 5.5.5. To locate where the generator meta tag is initialized, look for your admin-init.php file for your template and woo_version() function and woo_version_init() function should be there. Usually its under the includes folder within your theme source.

1
  • This didn't remove the <meta name="generator" content="Site Kit by Google 1.123.1" /> tag, from Google Site Kit, for me.
    – Nathan
    Commented Mar 29 at 19:52
5

At the bottom of the functions.php file add this following php snippet:

// hide the meta tag generator from head and rss
function disable_version() {
   return '';
}
add_filter('the_generator','disable_version');
remove_action('wp_head', 'wp_generator');
3

I found this source code of a plugin which states that it removes the auto-generated WP meta tags. You could try that.

  • Plugin Name: Remove WP Meta
  • Plugin URI: http://leekelleher.com/
  • Description: This plugin removes the auto-generated WP meta tags from each webpage.
  • Author: Lee Kelleher
4
  • Thanks! I've tried it with WP 4.0 and it works perfect. Commented Nov 8, 2014 at 17:09
  • Link-only solutions are no good. If the link breaks, it's useless. Provide the name of the plugin, and / or the relevant code here. Commented Jan 23, 2016 at 22:58
  • You are correct. I just added more information taken from the plugin comment section. Luckily the link was still working or otherwise I would not have known what plugin I suggested :)
    – user850010
    Commented Jan 24, 2016 at 12:13
  • FYI that method does not remove version numbers from e.g. RSS feeds, so disabling the entire function is considered better practice. Commented Feb 23, 2023 at 11:35
3

NO!

In case if it is hardcoded into your theme's template (i.e. in header.php),then you have to manually remove that!

Otherwise, use this full solution, to remove all version tags:

// ============ removing inbuilt WP meta-tag ===========  http://stackoverflow.com/q/16335347/2377343  ========== //
  //if included in wp_head
    add_action( 'after_setup_theme', 'my_wp_version_remover' ); function my_wp_version_remover(){
        remove_action('wp_head', 'wp_generator'); 
    }
  //clean all responses from VERSION GENERATOR
    add_filter('the_generator',             'rm_generator_filter'); 
    add_filter('get_the_generator_html',    'rm_generator_filter');
    add_filter('get_the_generator_xhtml',   'rm_generator_filter');
    add_filter('get_the_generator_atom',    'rm_generator_filter');
    add_filter('get_the_generator_rss2',    'rm_generator_filter');
    add_filter('get_the_generator_comment', 'rm_generator_filter');
    add_filter('get_the_generator_export',  'rm_generator_filter');
    add_filter('wf_disable_generator_tags', 'rm_generator_filter');
                                    function rm_generator_filter() {return '';}
// ========================================================== //
1
  • 2
    Man, this is a sledgehammer. It includes stuff to remove version parameters, which is not relevant to the question.... Commented Jan 23, 2016 at 23:00
3

This one finds the sitekit by Google, but can be modified for anything. Thanks to this article and his plugin.

add_action('get_header',function (){
    ob_start(function ($o) {
        return preg_replace('/\n?<.*?content="Site Kit by Google.*?>/mi','',$o);
    });
});
add_action('wp_head',function (){
    ob_end_flush();
   }, 992);
1

The following code gets rid of all generator tags in the Woo Framework. I have tested it with Woo Framework 6.0.4 and the theme Canvas 5.8.3:

// Remove the WooThemes version from the html headers
function no_woo_version ()
{
   return true;
}
add_filter ('wf_disable_generator_tags', 'no_woo_version');
1

/* You can use the the_generator filter to disable the meta generator tag. You’ll need to add the code below to the functions.php file of your theme*/

If you want to remove the generator XML or Comment for RSS, ATOM, etc used below the wordpress hook


add_filter( 'the_generator', '__return_null' );

0

If you made your ouw custom WordPress theme, there will be no problem with generator in meta, DO like i Did in samll sample. There will be no generator, if you will not declare it like some of your custom functions. I try to control all JS scripts and Styles of my theme like here. If i have, style from plugins, there some more Job needed.

but if you use, free theme, yes in 100% there will be generator. So add in File Function.php 1: http://sierra-group.in.ua/start-legkogo-rezhima-preprocesornoj-sborki-vashih-fajlov-stilej-i-skriptov.html/#custom-register-styles-sctiprs

function disable_version() { return '';}
add_filter('the_generator','disable_version');
remove_action( 'wp_head', 'wp_generator');
remove_action('wp_head', 'woo_version'); 
function no_woo_version (){   return true;}
add_filter ('wf_disable_generator_tags', 'no_woo_version');

Not the answer you're looking for? Browse other questions tagged or ask your own question.