Every time a scheduled post publishes → ALWAYS regenerate the slug from the title
add_action('publish_future_post', function($post_id) {
wp_schedule_single_event(time() + 60, 'fix_scheduled_slug', [$post_id]);
});
add_action('fix_scheduled_slug', function($post_id) {
$post = get_post($post_id);
if (!$post) {
return;
}
$new_slug = sanitize_title($post->post_title);
wp_update_post([
'ID' => $post->ID,
'post_name' => $new_slug,
]);
});
Leave a Reply