Remove All Meta Generators in WordPress. Code example open

Remove All Meta Generators in WordPress. Code example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
Tested: WordPress 6.4+
//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);

The remove_meta_generators function is used to remove all meta tags with the name=”generator” attribute from the HTML code.

The clean_meta_generators function is used to process HTML code before outputting it. It uses ob_start() to enable output buffering and then calls the remove_meta_generators function to remove meta tags with the name=”generator” attribute. This way, all generator meta tags will be removed from the HTML code before it is output.

The clean_meta_generators function is then given the get_header action to run when the page header is retrieved, and the wp_footer action to run when the page footer is rendered. This way the function will be applied to the HTML code on each page before it is rendered to remove the generator meta tags.

0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation