The get_the_generator_{$type} WordPress PHP filter allows you to modify the HTML output for the retrieved generator type. The dynamic part of the filter name, $type, refers to the generator type.
Table of contents
Usage
add_filter('get_the_generator_{$type}', 'your_custom_function', 10, 2);
function your_custom_function($gen, $type) {
// your custom code here
return $gen;
}
Parameters
$gen(string) – The HTML markup output towp_head().$type(string) – The type of generator. Accepts ‘html’, ‘xhtml’, ‘atom’, ‘rss2’, ‘rdf’, ‘comment’, ‘export’.
More information
See WordPress Developer Resources: get_the_generator_{$type}
Examples
Modify Atom generator output
Change the generator output for Atom feeds.
add_filter('get_the_generator_atom', 'modify_atom_generator', 10, 2);
function modify_atom_generator($gen, $type) {
$gen = '<generator uri="https://your-custom-uri.com" version="1.0">' . bloginfo('name') . '</generator>';
return $gen;
}
Add custom attribute to RSS2 generator
Add a custom attribute to the RSS2 generator.
add_filter('get_the_generator_rss2', 'add_custom_attr_to_rss2', 10, 2);
function add_custom_attr_to_rss2($gen, $type) {
$gen = str_replace('<generator>', '<generator custom-attr="your-value">', $gen);
return $gen;
}
Remove generator for HTML type
Remove the generator output for HTML type.
add_filter('get_the_generator_html', 'remove_html_generator', 10, 2);
function remove_html_generator($gen, $type) {
return '';
}
Change the RDF generator output
Modify the RDF generator output.
add_filter('get_the_generator_rdf', 'change_rdf_generator', 10, 2);
function change_rdf_generator($gen, $type) {
$gen = '<generator uri="https://your-custom-uri.com" version="1.0">' . bloginfo('name') . '</generator>';
return $gen;
}
Modify the Export generator output
Change the generator output for the Export type.
add_filter('get_the_generator_export', 'modify_export_generator', 10, 2);
function modify_export_generator($gen, $type) {
$gen = '<generator uri="https://your-custom-uri.com" version="1.0">' . bloginfo('name') . '</generator>';
return $gen;
}