You’ll need a two step process for that.
- Create a function that actually changes the slug (not rewrite it)
- Schedule an event in WordPress to run that function in every X hours.
Here are something to start with
function wpse402903_schedule_event() {
add_action( 'wpse402903_cron', 'wpse402903_cron_callback' );
if ( !wp_next_scheduled('wpse402903_cron') ) {
//Change 12 to your interval
wp_schedule_event( time(), 12 * HOUR_IN_SECONDS, 'wpse402903_cron' );
}
}
add_action( 'init', 'wpse402903_schedule_event' );
function wpse402903_cron_callback() {
$post_id = 123; //The ID of the Post
$postID = wp_insert_post( array(
'ID' => $post_id,
'post_name' => 'your-new-slug', //always use sanitize_title() if this generates dynamically.
));
}
The only drawback is the WP Cron. It acivates only if someone visits your site. For a site with regular traffic, this is not a problem though.