Skip to content

Instantly share code, notes, and snippets.

@WerdsWords
Created July 22, 2013 05:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WerdsWords/6051547 to your computer and use it in GitHub Desktop.
Save WerdsWords/6051547 to your computer and use it in GitHub Desktop.
#13: author_rewrite_rules
<?php
/**
* Change 'author' permalinks to 'contributors'
*
* @see WP_Rewrite::rewrite_rules()
*
* @param array $author_rewrite The authors rewrite rules.
*
* @return array The filter rewrites array.
*/
function wpdocs_contributors_rewrites( $author_rewrite ) {
$contributors = array(
'contributor/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]',
'contributor/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]',
'contributor/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&paged=$matches[2]',
'contributor/([^/]+)/?$' => 'index.php?author_name=$matches[1]'
);
$old = array();
// This relies on you registering a 'redirect' query var and handler.
// The handler would check for 'redirect' and apply a wp_redirect call where necessary.
foreach ( $author_rewrite as $endpoint => $query )
$old[$endpoint] = $query . '&redirect=1';
return array_merge( $old, $contributors );
}
add_filter( 'author_rewrite_rules', 'wpdocs_contributors_rewrites' );
@WerdsWords
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment