bbPressのパーマリンクを数字にする方法

bbPress
この記事は約2分で読めます。
シェアする:

以下のコード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);

その後、WordPress管理画面から設定→パーマリンクに行って、何もしないでそのまま一度保存して内容を反映させる。

コメント

寄付する

タイトルとURLをコピーしました