Wordpressでの案件で結構あるのが管理画面での表示について。一番よくあるのが管理画面の左側のメニューにある「投稿」の名前を任意のものに変更して欲しいというもの。
今回は実際にあった変更依頼を例にとって変更方法をご説明です。こちらもご要望ごとに文字の変更は必要ですが、基本的にコピペで完了しちゃいます。
まずはメニューの「投稿」やカテゴリーを一気に変更
この時の案件では店舗を固定ページでもカスタム投稿でもなく、投稿部分で作成することになったので、この部分をまず変更します。
おきまりのfunctions.phpに以下を入力
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
//管理メニュー「投稿」を店舗登録、「カテゴリー」を「地域」に、「タグ」を「業種」に変更 function change_post_label() { global $menu; global $submenu; $menu[5][0] = '店舗登録'; $submenu['edit.php'][5][0] = '店舗一覧'; $submenu['edit.php'][10][0] = '新規店舗登録'; $submenu['edit.php'][15][0] = '地域'; $submenu['edit.php'][16][0] = '業種'; } function change_object_label() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = '店舗'; $labels->singular_name = '店舗'; $labels->add_new = _x('追加', '店舗'); $labels->add_new_item = '店舗の新規追加'; $labels->edit_item = '店舗の編集'; $labels->new_item = '新規店舗'; $labels->view_item = '店舗を表示'; $labels->search_items = '店舗を検索'; $labels->not_found = '店舗が見つかりませんでした'; $labels->not_found_in_trash = 'ゴミ箱に店舗は見つかりませんでした'; } add_action( 'init', 'change_object_label' ); add_action( 'admin_menu', 'change_post_label' ); |
ここまでをざっくり解説
3行目のfunction change_post_label()の部分で管理画面の左メニュー部分を変更しています。
$menu[5][0] = ‘店舗登録’;が「投稿」だった部分ですね。
$submenu[‘edit.php’][5][0] = ‘店舗一覧’;
$submenu[‘edit.php’][10][0] = ‘新規店舗登録’;
$submenu[‘edit.php’][15][0] = ‘地域’;
$submenu[‘edit.php’][16][0] = ‘業種’;
そしてその後に続いているのが元は「投稿一覧」、「新規投稿」、「カテゴリー」、「タグ」だったところです。
こんな感じに変わりました。
カテゴリーやタグ(だったところ)の中身?も変更
これで終了でも十分な場合は良いのですが、各項目をクリックして登録や変更をする部分の名称なども変更していきます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
function change_taxonomies_label() { global $wp_taxonomies; $labels = $wp_taxonomies['category']->labels; $labels->name = '地域'; $labels->singular_name = '地域'; $labels->search_items = '地域を検索'; $labels->all_items = '地域一覧'; $labels->parent_item = '親地域'; $labels->parent_item_colon = '親地域:'; $labels->edit_item = '地域の編集'; $labels->view_item = '地域を表示'; $labels->update_item = '地域を更新'; $labels->add_new_item = '新規地域を追加'; $labels->new_item_name = '新規地域名'; $labels->not_found = '地域が見つかりませんでした。'; $labels->no_terms = '地域なし'; $labels = $wp_taxonomies['post_tag']->labels; $labels->name = '業種'; $labels->singular_name = '業種'; $labels->search_items = '業種を検索'; $labels->popular_items = '人気の業種'; $labels->all_items = 'すべての業種'; $labels->edit_item = '業種の編集'; $labels->view_item = '業種を表示'; $labels->update_item = '業種を更新'; $labels->add_new_item = '新規業種を追加'; $labels->new_item_name = '新規業種名'; $labels->separate_items_with_commas = '業種が複数ある場合はコンマで区切ってください'; $labels->add_or_remove_items = '業種の追加もしくは削除'; $labels->choose_from_most_used = 'よく使われている業種から選択'; $labels->not_found = '業種が見つかりませんでした。'; $labels->no_terms = '業種なし'; } add_action( 'init', 'change_taxonomies_label' ); |
こんな感じに元ある文字の「カテゴリー」を「地域」に、
「タグ」を「業種」に変更(するだけです)。
これでたいていの場所の名前が変更されるはずです。
こちらは元カテゴリーの登録画面。
こちらは元タグの登録画面。
元投稿一覧の部分も変わってます。
まとめ
左のメニュー部分だけだとちょっと中途半端は時があるので、
僕はいつも上の二つをセットで使って変更しています。
それがこちらです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
//管理メニュー「投稿」を店舗登録、「カテゴリー」を「地域」に、「タグ」を「業種」に変更 function change_post_label() { global $menu; global $submenu; $menu[5][0] = '店舗登録'; $submenu['edit.php'][5][0] = '店舗一覧'; $submenu['edit.php'][10][0] = '新規店舗登録'; $submenu['edit.php'][15][0] = '地域'; $submenu['edit.php'][16][0] = '業種'; } function change_object_label() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = '店舗'; $labels->singular_name = '店舗'; $labels->add_new = _x('追加', '店舗'); $labels->add_new_item = '店舗の新規追加'; $labels->edit_item = '店舗の編集'; $labels->new_item = '新規店舗'; $labels->view_item = '店舗を表示'; $labels->search_items = '店舗を検索'; $labels->not_found = '店舗が見つかりませんでした'; $labels->not_found_in_trash = 'ゴミ箱に店舗は見つかりませんでした'; } function change_taxonomies_label() { global $wp_taxonomies; $labels = $wp_taxonomies['category']->labels; $labels->name = '地域'; $labels->singular_name = '地域'; $labels->search_items = '地域を検索'; $labels->all_items = '地域一覧'; $labels->parent_item = '親地域'; $labels->parent_item_colon = '親地域:'; $labels->edit_item = '地域の編集'; $labels->view_item = '地域を表示'; $labels->update_item = '地域を更新'; $labels->add_new_item = '新規地域を追加'; $labels->new_item_name = '新規地域名'; $labels->not_found = '地域が見つかりませんでした。'; $labels->no_terms = '地域なし'; $labels = $wp_taxonomies['post_tag']->labels; $labels->name = '業種'; $labels->singular_name = '業種'; $labels->search_items = '業種を検索'; $labels->popular_items = '人気の業種'; $labels->all_items = 'すべての業種'; $labels->edit_item = '業種の編集'; $labels->view_item = '業種を表示'; $labels->update_item = '業種を更新'; $labels->add_new_item = '新規業種を追加'; $labels->new_item_name = '新規業種名'; $labels->separate_items_with_commas = '業種が複数ある場合はコンマで区切ってください'; $labels->add_or_remove_items = '業種の追加もしくは削除'; $labels->choose_from_most_used = 'よく使われている業種から選択'; $labels->not_found = '業種が見つかりませんでした。'; $labels->no_terms = '業種なし'; } add_action( 'init', 'change_object_label' ); add_action( 'admin_menu', 'change_post_label' ); add_action( 'init', 'change_taxonomies_label' ); |
ちなみにカスタム投稿や固定ページを使ってそれぞれに今回のような「店舗」などの項目を作り、「投稿」は「ブログ」や「ニュース」にする。
なんてことも結構あります。そんなときは「カテゴリー」や「タグ」はそのままでよかったりするので、
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
function change_post_label() { global $menu; global $submenu; $menu[5][0] = 'ニュース登録'; $submenu['edit.php'][5][0] = 'ニュース一覧'; $submenu['edit.php'][10][0] = '新規ニュース登録'; } function change_object_label() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = 'ニュース'; $labels->singular_name = 'ニュース'; $labels->add_new = _x('追加', 'ニュース'); $labels->add_new_item = 'ニュースの新規追加'; $labels->edit_item = 'ニュースの編集'; $labels->new_item = '新規ニュース'; $labels->view_item = 'ニュースを表示'; $labels->search_items = 'ニュースを検索'; $labels->not_found = 'ニュースが見つかりませんでした'; $labels->not_found_in_trash = 'ゴミ箱にニュースは見つかりませんでした'; } add_action( 'init', 'change_object_label' ); add_action( 'admin_menu', 'change_post_label' ); |
これだけで大丈夫かと思います。ご参考まで^^