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 );
}
}