#13: author_rewrite_rules

The author_rewrite_rules filter makes it possible to modify WordPress’ default rewrite rules for handling author pages.

It is evaluated in WP_Rewrite::rewrite_rules() in the wp-includes/rewrite.php file.

The author_rewrite_rules filter’s single argument takes the form of an array and contains the key/value rewrite pairs for author pages.

Side note: Altering the default author rewrite rules may cause 404’s with pages that were linked prior to the change. IF you’re going to modify the default rules, it is usually best to retain the original rules and set up redirects to the new permastructs. One method is to append a custom query var — such as ‘redirect’ value of ‘true’ — to the original rule(s), then adding a handler to redirect to the new permastruct if the custom query var is present. This way, you get new custom author rewrites and the old ones still work.

Example:

Let’s say you have a site that makes it a point to refer to credited authors as “contributors”. The following will alter your author rewrite rules to point to yoursite.com/contributor/name for author archives.

View the code example on Gist.

**Bonus: Example functions for adding a ‘redirect’ query var and parsing redirects for the old author permastruct.

View the bonus code example on Gist.

#8: get_the_generator_{$type}

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:

  1. string $gen The generator meta tag
  2. 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.