Removing WooCommerce Meta Generator Tag

In one of my post, I already discussed about the WordPress meta generator tag and have shown how to remove it. Today I will talk about similar meta tag. If you are using WooCommerce plugin on your WordPress site, by default you should see a meta generator tag on your site’s source code which looks something like this.

<meta name="generator" content="WooCommerce x.x.x" />

Generally speaking, even though this tag doesn’t seem to be harmful but it can reveal lots of security related information. Specially it could be an important tool for a site hacker to figure out the vulnerabilities of your site.

Worry not, there are ways to fix this problem real quick depending on the version of WC you are using on your server.
Before WooCommerce v2.1.0 Releases

<?php
function ib_remove_woocommerce_generator_tag() { 
   global $woocommerce;
   remove_action('wp_head', array($woocommerce,'generator')); }
add_action('woocommerce_init','ib_remove_woocommerce_generator_tag');
?>

Now, it seems like since WooCommerce 2.1.0 number of changes took place and the snippet mentioned above doesn’t work with the WC 2.1.0 and later versions. Upon little investigation it turned out that there are very specific hooks that generates the WooCommerce generator tag (HTML, xHTML format) and can easily be removed using the following snippet.
WooCommerce v2.1.0 and later Releases

<?php
function ib_remove_woocommerce_generator_tag(){
   remove_action('get_the_generator_html','wc_generator_tag', 10,2);
   remove_action('get_the_generator_xhtml','wc_generator_tag', 10,2); }
add_action('get_header','ib_remove_woocommerce_generator_tag');
?>

All you have to do now is to place this snippet on your theme’s “functions.php” page and update it. You are done.

References: remove_action, add_action, get_header.

Today In History

  •  
  •  

Comment

2 Comments

    AwranPublished: 4 years ago

    Thanks for the post but it doesn’t work actually, only “”remove_action(‘wp_head’, ‘wp_generator’);”” works but it will remove WordPress Meta Generator as well.

    Please if there is another way to remove only WooCommerce update your post

    Thanks

      Iftekhar BhuiyanPublished: 4 years ago

      Hello Awran, thank you very much for pointing out this issue. It seems like you are absolutely right on that and the initial snippet I added on this post doesn’t work with the latest version of WC. It has something to do with the core functions of WC that has changed since 2.1.0. However, I managed to figure it out and added the latest snippet that works with the latest version of WC. Thanks.

Leave a Reply

Note: Convet HTML, PHP, JavaScripts from HTMLify, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.