以下をテーマのfunctions.phpへ入れたら動作しましたよ
// The first part //
add_filter('author_rewrite_rules', 'no_author_base_rewrite_rules');
function no_author_base_rewrite_rules($author_rewrite) {
global $wpdb;
$author_rewrite = array();
$authors = $wpdb->get_results("SELECT user_nicename AS nicename from $wpdb->users");
foreach($authors as $author) {
$author_rewrite["({$author->nicename})/page/?([0-9]+)/?$"] = 'index.php?author_name=$matches[1]&paged=$matches[2]';
$author_rewrite["({$author->nicename})/?$"] = 'index.php?author_name=$matches[1]';
}
return $author_rewrite;
}
// The second part //
add_filter('author_link', 'no_author_base', 1000, 2);
function no_author_base($link, $author_id) {
$link_base = trailingslashit(get_option('home'));
$link = preg_replace("|^{$link_base}author/|", '', $link);
return $link_base . $link;
}
参考サイト(英語)
https://wp-snippet.com/snippets/remove-author-prefix-from-slug/
ただ、別のスラグと被った時にどうなるのか?という疑問は残るので、Edit Author Slugプラグインで「author」を別の文字に変更したほうがいいかも知れませんね。
404エラーが出るときやコードを削除して元に戻すときはページをリロードするか、パーマリンク設定画面開いて何もせずに更新すれば元に戻りました(あくまでも私の持っているテストサイトでの話です)。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/22 17:05