Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pm_detect_author_permalink($request) {
- global $wp;
- // Parse the URI
- // URL Format: blog/%author%
- preg_match('/blog\/([^\/]+)(?:\/page\/([\d]+))?/', $wp->request, $parts);
- if(!empty($parts[1])) {
- $author_slug = sanitize_title($parts[1]);
- $author = get_user_by('slug', $author_slug);
- if(!empty($author->user_login)) {
- $request = array(
- 'author_name' => $author->user_login
- );
- }
- // Support pagination
- if(!empty($parts[2])) {
- $request['paged'] = (int) $parts[2];
- }
- }
- return $request;
- }
- add_filter('request', 'pm_detect_author_permalink');
- function pm_change_author_base() {
- global $wp_rewrite;
- $wp_rewrite->author_base = 'blog';
- $wp_rewrite->author_structure = '/' . $wp_rewrite->author_base . '/%author%';
- }
- add_action('init', 'pm_change_author_base', 999);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement