Q.カスタム投稿タイプ名「プロジェクト」「イベント」「インフォメーション」を変更したい
カスタム投稿タイプ「プロジェクト」「イベント」「インフォメーション」の投稿タイプ名やスラッグを変更することはできますか?
A.下記のphpファイルの該当箇所を編集します
①「プロジェクト」の変更
編集するファイル:functions.php
編集する箇所:
// カスタム投稿 「プロジェクト」を追加 ----------------------------------------------------------------
if ( function_exists('register_post_type') ) {
$labels = array(
'name' => __('Project', 'tcd-w'),
'singular_name' => __('Project', '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('project', array(
'label' => __('Project', 'tcd-w'),
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'menu_position' => 5,
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'project'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'supports' => array('title','editor','thumbnail')
));
};
②「イベント」の変更
編集するファイル:functions.php
編集する箇所:
// カスタム投稿 「イベント」を追加 ----------------------------------------------------------------
if ( function_exists('register_post_type') ) {
$labels = array(
'name' => __('Events', 'tcd-w'),
'singular_name' => __('Events', '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('event', array(
'label' => __('Events', 'tcd-w'),
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'menu_position' => 5,
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'event'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'supports' => array('title','editor','thumbnail')
));
};
③「インフォメーション」の変更
編集するファイル:functions.php
編集する箇所:
// カスタム投稿 「インフォメーション」を追加 ----------------------------------------------------------------
if ( function_exists('register_post_type') ) {
$labels = array(
'name' => __('Information', 'tcd-w'),
'singular_name' => __('Information', '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('info', array(
'label' => __('Information', 'tcd-w'),
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'menu_position' => 5,
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'info'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'supports' => array('title','editor','thumbnail')
));
};
管理画面のメニュー「プロジェクト」「イベント」「インフォメーション」を変更したい場合は、’name’ の値を、URL等に表示されるスラッグを変更したい場合は、’rewrite’ の値である配列中の’slug’の値を任意にご変更ください。
例)
'name' => __('●●●')
'rewrite' => array('slug' => '●●●')
※パーマリンク変更を伴いますので、以前のスラッグは使用不可となります。
上記変更により404エラーが出た際は 設定>パーマリンク設定で変更を保存ボタンを押下します。(設定変更は不要で、ただ保存ボタンを押すだけで結構です。)
この記事は役に立ちましたか?
もし参考になりましたら、下のボタンで教えてください。
今後の記事作成の参考とさせて頂きます!