Random home page at each refresh between array of page IDs
I am trying to rotate 3 pages as my home page at refresh.
Currently I am using this in my functions.php:
?php
function my_homepage_redirect() {
if ( is_home() || is_front_page() ){
$page = get_posts( [
'post_type' = 'page',
'posts_per_page' = 1,
'orderby' = 'rand',
'fields' = 'ids'
] );
if ( empty( $page ) ){
return;
}
wp_redirect( get_permalink( $page[0] ) );
exit;
}
}
add_action( 'template_redirect', 'my_homepage_redirect' );
?
But I don't want a redirect. I'd like for the URL to stay domain.com.
Probably I need something like this (so that it just sets a page between the 3 as home page rather than redirecting), but how do I build this in functions.php?