- Navigate to the WordPress plugin directory of your development installation.
- Create a new directory called ch2-generator-filter.
- Navigate to this directory and create a new text file called ch2-generator-filter.php.
- Open the new file in a code editor and add an appropriate header at the top of the plugin file, naming the plugin Chapter 2 - Generator Filter.
- Add the following line of code to register a function that will be called when WordPress is preparing data to output the generator meta tag as part of the page header:
add_filter( 'the_generator', 'ch2gf_generator_filter', 10, 2 );
- Add the following code section to provide an implementation for the ch2gf_generator_filter function:
function ch2gf_generator_filter ( $html, $type ) {
if ( $type == 'xhtml' ) {
$html = preg_replace( '("WordPress.*?")',
'"Yannick Lefebvre"', $html );
}
return $html;
}
- Save and close the plugin file.
- Log in to the administration page of your development WordPress installation.
- Click on Plugins in the left-hand navigation menu.
- Activate your new plugin.
- Use a web browser to visit your website and display the page source. Searching for the keyword generator will reveal that the content generator meta tag has been modified and now reads:
<meta name="generator" content="Yannick Lefebvre" />