採用サイト制作に最適なWordPressテーマ「ISSUE」の機能概要

ワードプレステーマ別

TCDテーマLAW:カスタム投稿タイプ名「スタッフ」「お知らせ」を変更する

Q.Q.カスタム投稿タイプ名「スタッフ」や「お知らせ」を変更したい

カスタム投稿タイプ「スタッフ」「お知らせ」の投稿タイプ名やスラッグを変更することはできますか?

A.下記のphpファイルの該当箇所を編集します

①「スタッフ」の変更
編集するファイル:functions.php
編集する箇所:

if ( function_exists('register_post_type') ) {
 $labels = array(
  'name' => __('Staff', 'tcd-w'),
  'singular_name' => __('Staff', 'tcd-w'),
  'add_new' => __('Add New', 'tcd-w'),
  'add_new_item' => __('Add New Item', 'tcd-w'),
  'edit_item' => __('Edit', 'tcd-w'),
  'new_item' => __('New item', 'tcd-w'),
  'view_item' => __('View Item', 'tcd-w'),
  'search_items' => __('Search Items', 'tcd-w'),
  'not_found' => __('Not Found', 'tcd-w'),
  'not_found_in_trash' => __('Not found in trash', 'tcd-w'), 
  'parent_item_colon' => ''
 );

 register_post_type('staff', array(
  'label' => __('Staff', 'tcd-w'),
  'labels' => $labels,
  'public' => true,
  'publicly_queryable' => true,
  'menu_position' => 5,
  'show_ui' => true,
  'query_var' => true,
  'rewrite' => array('slug' => 'shain'),
  'capability_type' => 'post',
  'has_archive' => true,
  'hierarchical' => true,
  'supports' => array('title','editor','thumbnail')
 ));
};

②「お知らせ」の変更
編集するファイル:functions.php
編集する箇所:

if ( function_exists('register_post_type') ) {
 $labels = array(
  'name' => __('News', 'tcd-w'),
  'singular_name' => __('News', 'tcd-w'),
  'add_new' => __('Add New', 'tcd-w'),
  'add_new_item' => __('Add New Item', 'tcd-w'),
  'edit_item' => __('Edit', 'tcd-w'),
  'new_item' => __('New item', 'tcd-w'),
  'view_item' => __('View Item', 'tcd-w'),
  'search_items' => __('Search Items', 'tcd-w'),
  'not_found' => __('Not Found', 'tcd-w'),
  'not_found_in_trash' => __('Not found in trash', 'tcd-w'), 
  'parent_item_colon' => ''
 );

 register_post_type('news', array(
  'label' => __('News', 'tcd-w'),
  'labels' => $labels,
  'public' => true,
  'publicly_queryable' => true,
  'menu_position' => 5,
  'show_ui' => true,
  'query_var' => true,
  'rewrite' => array('slug' => 'news'),
  'capability_type' => 'post',
  'has_archive' => true,
  'hierarchical' => true,
  'supports' => array('title','editor','thumbnail')
 ));
};

管理画面のメニュー「スタッフ」や「お知らせ」を変更したい場合は、’name’ の値を、URL等に表示されるスラッグを変更したい場合は、’rewrite’ の値である配列中の’slug’の値を任意にご変更ください。

例)

'name' => __('●●●')
'rewrite' => array('slug' => '●●●')

※パーマリンク変更を伴いますので、以前のスラッグは使用不可となります。
上記変更により404エラーが出た際は 設定>パーマリンク設定で変更を保存ボタンを押下します。(設定変更は不要で、ただ保存ボタンを押すだけで結構です。)

この記事は役に立ちましたか?

もし参考になりましたら、下のボタンで教えてください。
今後の記事作成の参考とさせて頂きます!

同じテーマのカスタマイズ記事