概要説明
?author=1などWordPressサイトのURLの最後に付けてアクセスを行うと投稿者アーカイブページにリダイレクトされます。こちらのリダイレクトを無効にしたい時のカスタマイズ。
コード
functions.php
/*----------------------------------------------------
/?author=x でアクセスした時のリダイレクトを無効にする
----------------------------------------------------*/
if ( !function_exists( 'disable_author_archive_redirect' ) ){
// 管理画面以外
if ( !is_admin() ) {
function disable_author_archive_redirect() {
if(isset($_SERVER['QUERY_STRING'])){
if( preg_match('/author=([0-9]*)/i', $_SERVER['QUERY_STRING']) and !preg_match('/post_author=/i', $_SERVER['QUERY_STRING']) ){
wp_redirect( home_url() );
exit;
}
}
}
add_action('init', 'disable_author_archive_redirect');
}
}



