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

ワードプレステーマ別

TCDテーマMAXX:カスタム投稿タイプで自動的に表示される文言とスラッグ(URL)を変更する方法

Q.カスタム投稿タイプ名を変更したい

多くのTCDテーマでカスタム投稿を実装しておりますが、ニュースやお知らせ以外にもSTORYではギャラリー、MAXXではプログラムなど作成するサイトによっては、名前やスラッグ(URL)を変更したいものがあると思います。

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

そのため、最近のTCDテーマではテーマオプションから変更できるようにしております。
該当しないテーマの場合には、ご自身でのカスタマイズが必要になりますが、以下の方法を参照してください。
MAXXテーマのプログラムをMUSICにしたい時などを例にご説明します。

【MAXXの場合】
編集するファイル:functions.php
編集する箇所:

// カスタム投稿 「プログラム」を追加 ----------------------------------------------------------------
if ( function_exists('register_post_type') ) {
 $labels = array(
  'name' => __('Program', 'tcd-w'),
  'singular_name' => __('Program', '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('program', array(
  'label' => __('Program', 'tcd-w'),
  'labels' => $labels,
  'public' => true,
  'publicly_queryable' => true,
  'menu_position' => 5,
  'show_ui' => true,
  'query_var' => true,
  'rewrite' => array('slug' => 'program'),
  'capability_type' => 'post',
  'has_archive' => true,
  'hierarchical' => false,
  'supports' => array('title','editor')
 ));


編集するファイル:functions.php
編集する箇所:

// カスタム投稿 「プログラム」を追加 ----------------------------------------------------------------
if ( function_exists('register_post_type') ) {
 $labels = array(
  'name' => __('Program', 'tcd-w'),
  'singular_name' => __('MUSIC', '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('program', array(
  'label' => __('Program', 'tcd-w'),
  'labels' => $labels,
  'public' => true,
  'publicly_queryable' => true,
  'menu_position' => 5,
  'show_ui' => true,
  'query_var' => true,
  'rewrite' => array('slug' => 'Music'),
  'capability_type' => 'post',
  'has_archive' => true,
  'hierarchical' => false,
  'supports' => array('title','editor')
 ));

下記の図のような管理画面のメニュー「プログラム」を変更したい場合は、’name’ の値を変更してください。

下記の図のようなURL等に表示されるスラッグを変更したい場合は、’rewrite’ の値である配列中の’slug’の値を任意にご変更ください。

例)

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

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

※今回ご案内しているfunctions.phpは極めて重要なファイルです。
このファイル内に構文上のミス等がございますと、管理画面を含めサイト全体が表示されなくなることがございます。
もしそうした現象が発生いたしましたら、バックアップしておいたfunctions.phpを
FTP経由で同名ファイルに上書きアップロードすることで元の状態にお戻しください。

■LAWの場合
https://tcd-manual.net/?p=2000
■SKINの場合
https://tcd-manual.net/?p=3618

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

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

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