The <meta name="generator">
tag in WordPress reveals the version of WordPress, themes, or plugins your site uses. While seemingly harmless, this information can be a security risk, as it makes your site a target for exploits specific to those versions
This article provides comprehensive guide to removing the meta generator tag from your WordPress Website.
Before proceeding, it's highly recommended to back up your WordPress site. This ensures you can restore your site if anything goes wrong.
functions.php
FileThis method is one of the most common and straightforward ways to remove the meta generator tag.
functions.php
file: You can access this file via FTP or through the WordPress theme editor (Appearance > Theme Editor).remove_action('wp_head', 'wp_generator');
This method primarily targets the core WordPress generator tag. To remove theme-specific generator tags, you might need additional code.
Themes, like Woo Framework, often add their own generator tags. To remove these, you need to identify the function responsible for adding the tag and then remove the corresponding action.
admin-init.php
file for your template and the woo_version()
function:remove_action('wp_head', 'woo_version');
This method uses PHP's preg_replace
function to remove any meta generator tag, regardless of its content. This approach is more robust but requires careful implementation.
functions.php
file://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);
ini_set('output_buffering', 'on');
turns on output bufferingremove_meta_generators
function uses a regular expression ($pattern
) to find and replace any <meta>
tag containing "generator" with an empty string.ob_start
captures the entire HTML output, allowing the regex to work across the whole document.template_redirect
ensures the function runs before the page is sent to the browser.wp_footer
closes the buffer.Several plugins are available in the WordPress repository that can remove meta generator tags.
While plugins offer an easy solution, be sure to choose reputable ones with good reviews and regular updates.
functions.php
file, not the parent theme's file.Removing meta generator tags in WordPress is a simple yet effective way to enhance your site's security . By following the methods outlined in this article, you can eliminate these tags and reduce potential risks. Whether you choose to modify your functions.php
file or use a plugin, always back up your site beforehand and test your changes thoroughly.