..あなたがより多くを知っているここ
カスタム
にデフォルトを>設定パーマリンクを選択して行きます。 テーマののfunctions.phpファイルにこのコードを配置してみてください。
add_filter('post_link', 'custom_permalink', 10, 3);
function custom_permalink($permalink, $post, $leavename) {
// Get the categories for the post
$category = get_the_category($post->ID);
if ( !empty($category) && $category[0]->cat_name == "News") {
$permalink = trailingslashit(home_url('/'. $post->post_name .'-'. $post->ID .'/'));
}
return $permalink;
}
add_action('generate_rewrite_rules', 'custom_rewrite_rules');
function custom_rewrite_rules($wp_rewrite) {
// This rule will will match the post id in %postname%-%post_id% struture
$new_rules['^([^/]*)-([0-9]+)/?'] = 'index.php?p=$matches[2]';
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
return $wp_rewrite;
}
これあなたが投稿をしたいパーマリンク構造を設定します:
彼がすべてではないため、唯一の特定のカテゴリに変更したい
、してください質問を読む –
他の解決策は私の2番目の答えにあります。ここにあるのは https://wordpress.org/support/topic/change-permalink-for-one-category-only –