我想你可以过滤wp_unique_post_slug
并让它返回帖子的原始slug,但我不确定这可能会有什么副作用:
add_filter( \'wp_unique_post_slug\', function( $slug, $post_id, $post_status, $post_type, $post_parent, $original_slug ) {
if ( $post_type == \'post\' )
$slug = $original_slug;
return $slug;
}, 10, 6 );
下面是如何附加post ID而不是
-2
:
add_filter( \'wp_unique_post_slug\', function( $slug, $post_id, $post_status, $post_type, $post_parent, $original_slug ) {
if ( $post_type == \'post\' && $slug != $original_slug )
$slug = preg_replace( \'#\\-[0-9]+$#\', \'-\' . $post_id, $slug );
return $slug;
}, 10, 6 );