以下のコードをfunctions.phpに入れる。
// Rewrite rule for numeric slugs in bbPress topics
function bbpress_numeric_permalink_structure() {
add_rewrite_rule(
'^forums/topic/([0-9]+)/?$',
'index.php?post_type=topic&p=$matches[1]',
'top'
);
}
add_action('init', 'bbpress_numeric_permalink_structure');
// Generate custom numeric permalink for bbPress topics
function bbpress_custom_topic_permalink($post_link, $post, $leavename) {
if ('topic' === get_post_type($post)) { // Only apply to BBPress topics
return home_url('forums/topic/' . $post->ID); // Numeric permalink with "forum" prefix
}
return $post_link;
}
add_filter('post_type_link', 'bbpress_custom_topic_permalink', 10, 3);
コメントを残す