Post Slug Regenerate if Some Plugin or Code Block it In Scheduled Post.

Written by

in

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,
]);
});

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat Icon
Preview