questions

How to remove the Meta Generator Tag WordPress

Rate this post

Sorry to repeat this question again, but this drives me crazy?

How can I remove the wordpress 5.6.1 meta tag from the header in my wordpress template?

<meta name="generator" content="WordPress 5.6.1" />

I tried all code snippets that I found on the internet and placed it in the functions.php page of my theme and child theme. So code snippets like below do not work in my case:

// remove version from head
   remove_action('wp_head', 'wp_generator');

// remove version from rss
   add_filter('the_generator', '__return_empty_string');

// remove version from scripts and styles
   function collectiveray_remove_version_scripts_styles($src) {
      if (strpos($src, 'ver=')) {
        $src = remove_query_arg('ver', $src);
      }
      return $src;
        }
   add_filter('style_loader_src', 'collectiveray_remove_version_scripts_styles', 9999);
   add_filter('script_loader_src', 'collectiveray_remove_version_scripts_styles', 9999);

I also commented the code add_filter from the default-filters.php page, but this didn’t help either:

add_action( 'wp_head', 'wp_generator' );

So my conclusion must be that info about the wordpress version must be added somewhere else or in a later stage?

Are there any tips where I could start looking after and what specific piece of code I should look for? Is the version number stored somewhere in the db? Is there specific code that is executed after functions.php that can overrule the initial removal by the code that seems to work perfectly elsewhere? I don’t think the version number is hardcoded ad I did not find it with multiple keyword searches.

I am using wordpress 5.6.1 with a third-party theme. I made modifications, so I am using the child theme. I modified the prefix of my database tables (in case it would matter). My site is not yet online.

Based on the comment of Peter, I digged a bit further, but still no succes…

In my header.php of my theme, there is only mentionned to use the wp_head function:

<?php wp_head(); ?>

I have commented out the wp_head function in wp-includes\general-template.php:

function wp_head() {
/**
 * Prints scripts or data in the head tag on the front end.
 *
 * @since 1.5.0
 */
do_action( 'wp_head' );
}

I have commented out the function wp_generator in wp-includes\general-template.php

function wp_generator() {
/**
 * Filters the output of the XHTML generator tag.
 *
 * @since 2.5.0
 *
 * @param string $generator_type The XHTML generator.
 */
the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
}

I commnented out a few more instances related to wp_head. None of them have the desired result. In my theme there is no specific function appearing related to wp_head.

I have no clue how to solve this further?

 

✔️Solution:

I always use the following filter hook, plus remove_action hook. They work seamlessly fine!!!

function disable_wp_version(){
  return '';
}
add_filter('the_generator', 'disable_wp_version');

remove_action('wp_head', 'wp_generator');

Because pages get cached, IT’S VERY IMPORTANT TO CHECK THEM IN AN INCOGNITO(CHROME) / PRIVATE(FIREFOX) WINDOW. OR TRY TO DELETE YOUR BROWSER CACHE, BEFORE YOU TEST THOSE HOOKS!!!

I just tested them out on “2021” wordpress core default theme as well as a custom theme, they still work fine! (WordPress 5.6)

Leave a Reply

Your email address will not be published.

Back to top button