The get_the_generator_{$type}
filter allows you to modify the generator meta tag provided by WordPress in certain contexts.
It is evaluated in get_the_generator()
in the wp-includes/general-template.php file.
get_the_generator_{$type}
is a dynamic filter, meaning part of the filter tag changes based on the context. It accepts 2 arguments:
- string
$gen
The generator meta tag - string
$type
The generator type
The dynamic portion of the filter tag, $type
accepts html
, xhtml
(default), atom
, rss2
, rdf
, comment
, or export
. When you add your filter, the tag takes the form of get_the_generator_html
or get_the_generator_xhtml
and so on.
Example:
Sometimes people will use a filter to disable the generator tag altogether, termed “security by obscurity”. The following example instead tries to have a little fun with the generator tag by replacing the WordPress version number with its corresponding jazz musician! We’ll filter on the default xhtml
context.
This is a great project, thank you for your work on this.
If I could just offer one suggestion, it would be to use a function prefix in your sample code, like for example fotd_. So the above function would then be named fotd_mess_with_the_generator.
I know that this is just demonstration code, but unfortunately a lot of people just copy-paste the whole thing and just change the innards of the function, not the rest. So this is why I think it would be best to write as you would for a real project, even if it is just sample code.
This is something I would like to see being used consistently in the Codex and other tutorials as well.
That’s a pretty valid point. I generally try to use a fake textdomain to promote responsible localization, so I guess it hadn’t occurred to me that I should be prefixing in this context as well.
I’ll have to figure out what prefix I could use instead of ‘fotd’. Maybe ‘docs’ or something — mostly so I don’t have to re-prefix when examples get transferred to the Codex/Code Reference in the future.
Using a ‘wpdocs’ prefix is a lot better than my suggestion. Thanks for implementing this!
Week 1 Recap: Filters 1-12 – Filters of the Day