teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

補足の追加。

2016/04/19 13:29

投稿

kei344
kei344

スコア69625

answer CHANGED
@@ -32,4 +32,30 @@
32
32
  }
33
33
  }
34
34
  add_action( 'init', 'only_my_author_archive' );
35
- ```
35
+ ```
36
+
37
+ ---
38
+
39
+ **追記2:**
40
+
41
+ カノニカル時に利用されているであろう '%author%' を使っている(記述がある)のが `get_author_posts_url` `get_permalink` の2つのみで、「Edit_Author_Slug」が使用しているのが `get_author_posts_url` 内の `author_link` フックなので、ひとまずこれでいけそう。
42
+
43
+ ```PHP
44
+ add_filter( 'author_rewrite_rules', '__return_empty_array' );
45
+ function my_author_link( $link = '', $user_id = 0 ) {
46
+ if ( $user_id > 0 ) {
47
+ $link = home_url( user_trailingslashit( '/author/'.$user_id ) );
48
+ }
49
+ // Return the link.
50
+ return $link;
51
+ }
52
+ add_filter( 'author_link', 'my_author_link', 20, 2 );
53
+ ```
54
+
55
+ (参考)
56
+
57
+ 【get_author_posts_url() | Function | WordPress Developer Resources】
58
+ [https://developer.wordpress.org/reference/functions/get_author_posts_url/](https://developer.wordpress.org/reference/functions/get_author_posts_url/)
59
+
60
+ 【get_permalink() | Function | WordPress Developer Resources】
61
+ [https://developer.wordpress.org/reference/functions/get_permalink/](https://developer.wordpress.org/reference/functions/get_permalink/)

1

補足の追加。

2016/04/19 13:29

投稿

kei344
kei344

スコア69625

answer CHANGED
@@ -14,4 +14,22 @@
14
14
 
15
15
 
16
16
  【投稿者アーカイブを無効化してWordPressのユーザ名を隠す方法 | ウェブコンテンツウェブコンテンツ】
17
- [http://www.webcontent.jp/no-author-archive/](http://www.webcontent.jp/no-author-archive/)
17
+ [http://www.webcontent.jp/no-author-archive/](http://www.webcontent.jp/no-author-archive/)
18
+
19
+ ---
20
+
21
+ **追記:**
22
+ > 投稿者アーカイブが利用できなくなるのは避けたいので、
23
+ > author/admin ではなく author/1 にリダイレクトする
24
+
25
+ これでは?
26
+
27
+ ```PHP
28
+ function only_my_author_archive() {
29
+ if( $_GET[ 'author' ] && $_GET[ 'author' ] > 0 ){
30
+ wp_redirect( home_url( '/author/'.intval( $_GET[ 'author' ] ) ) );
31
+ exit;
32
+ }
33
+ }
34
+ add_action( 'init', 'only_my_author_archive' );
35
+ ```