Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress - How do I remove meta generator tags?

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?

like image 870
John Avatar asked May 02 '13 10:05

John


People also ask

How do I remove meta tags?

Under Page Management, click the Meta Tag Manager link. The Meta Tag Manager form appears. From the list of meta tags, select the one you want to delete. Click the Delete button.

How do I hide meta data in WordPress?

On your theme visit the WordPress Theme Options section under Appearance > Theme Options and then navigate to the General tab. Once you have navigated to the proper place, you can go to the section with the sliders and simply click the slider to hide or show the post meta.

How do you remove meta tags in HTML?

You could use the following javascript to remove the tags: $("meta[name='viewport']"). remove();


2 Answers

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

remove_action( 'wp_head', 'wp_generator' );
like image 188
lmmendes Avatar answered Oct 15 '22 11:10

lmmendes


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 4.7.2. 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('get_header', '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

like image 24
webbernaut Avatar answered Oct 15 '22 11:10

webbernaut