wordpress スラッグが日本語の場合自動で変換する 2022年1月8日
Tag:

wordpress スラッグが日本語の場合自動で変換する

1.functions.phpに下記を追加

add_action( 'create_term', 'post_taxonomy_auto_slug', 10, 3 );
function post_taxonomy_auto_slug( $term_id, $tt_id, $taxonomy ) {
  if ( $taxonomy !== 'category' ) return; // category のみ処理

  $term = get_term( $term_id, $taxonomy );
  if ( ! $term || is_wp_error( $term ) ) return;

  if ( preg_match( '/(%[0-9a-f]{2})+/', $term->slug ) ) {
    $args = array(
      'slug' => $taxonomy . '-' . $term_id
    );
    wp_update_term( $term_id, $taxonomy, $args );
  }
}

New

Aechive

Tag

css Facebook facebookカスタマイズ Facebookページ font functions.php google NEWマーク RSS single.php webツール WEBデザインツール Wordpress アーカイブ カスタム カスタムフィールド カスタムフィールドテンプレート カスタム投稿 カテゴリー カレンダー サイドバー ターム テキスト テンプレートタグ プラグイン ヘッダ ページ ポップアップ メニュー 並び替え 並べ替え 人気 便利 分岐 印刷 年別アーカイブ 投稿 投稿記事 改行 文字数 文法チェック 最新記事 月別アーカイブ 特定カテゴリー 画像