You can redirect users from home page to random page with this code (paste it to your functions.php)
function my_homepage_redirect() {
if ( is_home() || is_front_page() ){
$page = get_posts( [
'post_type' => 'post',
'posts_per_page' => 1,
'category' => 1, // your category ID
'orderby' => 'rand',
'fields' => 'ids'
] );
if ( empty( $page ) ){
return;
}
wp_redirect( get_permalink( $page[0] ) );
exit;
}
}
add_action( 'template_redirect', 'my_homepage_redirect' );
If you want to pick random page OR random post, you can modify the ‘post_type’ parameter:
'post_type' => [ 'post', 'page' ],
Related Posts:
- How to show a post single post in page template
- Theme’s page.php and index.php template files are confusing me
- Conditional get template part
- I want to duplicate homepage for all my pages
- is_front_page and is_home are not working in page.php
- WordPress custom login and register page problem?
- Is there a universal slug for static homepage?
- How To Create A Paginated List Of All Categories On My Site?
- Password protected posts redirects
- Overriding page template using page_template filter
- How to redirect WordPress home page to custom static HTML page
- Loading page content into a variable in template
- Capturing arbitrary semantic URL arguments
- How do I display the text inside the WP editor for a page with a custom template?
- Dynamically assign same page template to child page as parent
- What content should go in index.php?
- How to pass a numeric id to a page template?
- How can I dynamically load another page template to provide an alternate layout of the posts?
- get url page template
- Posts archive index pagination in a static page custom query
- How to Set a Custom Template for Blog Posts
- How can I have a static title on my blog page?
- Use is_category(), is_tag(), … in functions.php
- How do I add a body class to specific pages?
- How to list all titles of posts on a specific page?
- How to handle a missing page.php?
- Customize edit.php Pages listing in dashboard to show only pages with a particular template applied?
- Programatically switch page template?
- remove page template from dropdown?
- Export csv and force download in template page
- WPML in custom page templates
- Why (and how?) is get_header() erasing all my stuff?
- get_pages — parent vs child_of?
- How to pass outside function to WP_REST_Request
- page.php not displaying content
- WP-CLI not setting page template with page_template=”template-name.php”
- Create a page template with No Footer
- Register/Get sidebar?
- How to make text show up – new page template
- using the loop with a custom table
- Verify if the current page has at least one published child
- Page-loop is looping content from custom loops on the same site. How to avoid that?
- how to remove all body classes in wordpress
- Custom Post Type Archive template page not found
- How can I conditionally show different home page templates based on whether or not the user is logged in?
- Add #sidebar-2 to a custom page template
- What is wrong with my page.php?
- wp_redirect goes to infinity loop
- Single page Template for pages that begin with ‘confirmation-‘
- What content to use for inserting images
- How to Use index.php file for “Blog” Page And this is Not a Home Page
- Display one post in different formats conditionally
- get_avatar() as backround image
- get_the_excerpt() inside WP_Query – link URL Incorrect
- Change text size and color for tags and category meta description on product page
- Strip from the_tags() output
- How to make Dynamic Page Template based on Post ID’s
- Template Tag Does Not Work in Page Template
- Contact template doesnt appear in page template options
- Does get_template_part() content gets parsed if it’s not executed?
- Get_template_part seems to be ignoring my template
- Displaying posts on homepage – Template Page
- Proper way to create custom static page
- How can I correctly redirect user to the submitted post and define a template for each new post in WordPress?
- How to display all child/sub pages from all parent pages?
- Find php file anywhere in folder and subfolder from template
- Random home page at each refresh between array of page IDs
- WordPress page template to show posts as per category dynamically
- page.php template file render a core gutenberg component programmatically
- Subpage is redirecting to spam site
- How to integrate custom HTML template in a premium wordpress theme?
- How to load page template according to the Searched Page
- Set page template automatically according to parent slug
- How to display the contents of URL1 when user visits URL2
- How to require specific PHP files for specific templates
- Static page won’t identify template
- Change Front page displays settings conditionally when user is online
- Restrict Access to Logged-In Users Page Template
- What is the best way to manage pages content?
- Add additional templates to the templates drop down on add page menu [duplicate]
- Custom templates stopped working
- .htaccess help to a beginner
- Single page theme: Can I render other pages with their respective themes within another page?
- Special 404 header page
- change the Theme dynamically
- How can I set full width page layout in a default post page?
- E-Commerce Products Page Sidebar Formatting
- Lead Generation with Cookies in WordPress
- Recents posts pulling from different post type
- trying to add custom landing page to Twenty Eleven- can’t get rid of Twenty Eleven header/container? [duplicate]
- Template tag for /page/# structure
- Fetching Image from other post/page with custom type
- wordpress header leaks into body in a specific template
- Display child page on parent
- Utilizing the template hierarchy while storing page templates in a subdirectory
- Show page name in browser
- How do I create a page template that doesn’t show URL, sidebar, nav menu, footer?
- Animation as shown in the link
- Custom page template not working on mobile
- How do I update the SEO information on dynamic pages being generated from template_include?