Not tested well but you can try this.
add_action( 'template_redirect', 'my_homepage_redirect' );
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;
}
// update the front page id option according to the page id
update_option( 'page_on_front', $page[0]);
}
}
Related Posts:
- My homepage’s width has reduced and I can´t fix it [closed]
- Page editor missing Templates drop down
- How to find the posts page (home page) programatically
- How to edit contents of dynamic_sidebar()?
- I put my blog on a subpage, how do I get page title?
- How to hide/redirect the author page
- Need to give custom page template for each language in WPML
- Templates & CSS – Proper Programming Practice?
- Create Page that uses specific template
- Post formats template
- index.php template is used instead of blog page
- Hide Front-End Admin Bar Including 32 px Spacing
- What is a good way to present templated content in WordPress?
- Adding variable to get_template_part
- How to apply a custom template for posts by default?
- How to move style from template file to section?
- Subpage template
- How to create a wordpress template without using any page
- Advanced Custom Fields – display when specific template used?
- how to make a home page for wordpress custom theme
- How do I find the directory of a page template?
- Missing ‘Page Attributes’
- how to use custom page template in a page?
- the_excerpt producing empty output
- Conditionally display different images before the content in a page template
- Is there a way to set different post templates for parent posts and child posts in the same post type?
- Change wp-signup.php Page Template
- How to remove the Template drop down, but keep Parent and Order
- Templates have disappeared from drop down lists
- One of my pages uses the archive.php template only. Why?
- Getting pages filtered by template assigned
- Get link to a specific template file [closed]
- Default Template Selected After Changes in Elementor [closed]
- Use same page template for parent and child pages in a theme
- displaying category and subject posts
- How to duplicate a page template but make minor changes to the header?
- Adding Query to Custom Page Template
- get_file_data to read data for Custom Template File?
- Page attributes missing
- wp_enqueue_style and different styles for blog template
- Page template option missing
- How do I get the page template name chosen?
- How can I add text to a specific ‘Edit Page’?
- get_header(), get_footer() from plugin template
- What template is used for viewing Media Library Files?
- Page template for a site from network
- Force WordPress to NOT display the manual excerpt
- Undefined get_header function
- Single-page.php template file name not shown
- How to display custom post type?
- Hard Coding Components on a Client Specific Websites
- Will placing custom templates in sub directory break any native WordPress functionality
- Organize template parts and page templates in folders in regards of template hierarchy
- Blog page won’t show Blog template
- templates with page teasers Or Featured Items
- Search button click sends to single-custom_post_type instead staying at the same page
- Display a custom 404 page without a redirect
- How can I make custom page templates work on child theme?
- Change Page Template Based on URL Rewrite in WordPress
- Nested Page Template not showing in page attributes
- Creating custom post-listing templates in twentyseventeen child theme
- Custom Homepage As Single Page or Custom Post Type?
- When to use content-pagename.php?
- Submit form to another template (ugly url)
- Page Templates Used in Custom Post Type
- custom template – override plugin template in child theme – issue with scripts
- Is this the best way to complete disable category archive pages?
- Is there a way to share a template/markup with the JSON API so that it doesn’t need to be declared both in PHP and in JS?
- How to install a wordpress website template on an existing website?
- Custom Archive with Content for Custom Post Type
- Page.php vs Single.php
- html blog template to wordpress template
- How to duplicate a template in wordpress site editor?
- Customizing get_the_excerpt() to specific length and “Read More” output.
- How to redirect WordPress home page to custom static HTML page
- Remove navigation from header in custom page template
- Change site template from php
- Display HTML only if Custom Field has a Value
- how to create template path for external (include) .js file
- home.php not loading
- get_search_link() redirects to 404 template page
- New custom nev not working [closed]
- Search results when none found – stay on page they were on
- Get URL of current post but not the page number
- Is template name always same as directory name?
- Author template help. How to check if field exists in the profile?
- Change default template in the block editor (Gutenberg)
- How do I create post template for different taxonomy
- Ip2location plugin in my template header?
- Load php file with jquery in single.php
- Print different parts of content in template
- How can I pass a variable from a template to header.php of a theme
- Using custom post types within a section of a template
- using a template for more then 1 page
- Including 2 Negative Is_Template Conditionals in header.php [closed]
- Unload templates; disable parent Template Parts using only “theme.json”
- In 2016 theme, how can I force all single attachment posts to use content-attachment.php rather than image.php?
- WordPress “Blog” template hierarchy
- How to force a Custom Post Type template by filename
- order archive page by title in wp twenty twenty-four template