/**
* unifying slug of the CPT by adding post id in the slug
*
* @param $slug
* @param $post_id
* @param $post_status
* @param $post_type
* @param $post_parent
* @param $original_slug
*
* @return null|string|string[]
*/
function custom_permalink_slug_wp_unique_post_slug_callback( $original_slug, $slug, $post_id, $post_status, $post_type, $post_parent ) {
// her we have to mention which post type to support
$support_post_type = array( 'post', 'book' );
if ( in_array( $post_type, $support_post_type ) ) {
$slug = $slug . '-' . $post_id;
}
return $slug;
}
add_filter( 'pre_wp_unique_post_slug', 'custom_permalink_slug_wp_unique_post_slug_callback', 100, 6 );
Скопируйте приведенный выше код и вставьте его в файл functions.php дочерних тем.
Я проверил это, и он отлично работает для меня