Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Use a dedicated WordPress route, query one published post with WP_Query and orderby => 'rand', then send the visitor to its permalink with wp_safe_redirect() and exit. The example below creates a /random-post/ endpoint without affecting ordinary requests.

Recommended server-side implementation

Add this code to a site-specific plugin or your child theme’s functions.php. A plugin is not required, but keeping custom behavior in a site plugin prevents it from disappearing when the theme changes.

<?php
add_action( 'template_redirect', function () {
    // Change this condition to match your dedicated endpoint or page.
    if ( ! is_page( 'random-post' ) ) {
        return;
    }

    $random_post = new WP_Query( array(
        'post_type'           => 'post',
        'post_status'         => 'publish',
        'posts_per_page'      => 1,
        'orderby'             => 'rand',
        'no_found_rows'       => true,
        'ignore_sticky_posts' => true,
    ) );

    if ( ! $random_post->have_posts() ) {
        status_header( 404 );
        wp_die( 'No eligible posts are available.' );
    }

    $random_post->the_post();
    $destination = get_permalink();
    wp_reset_postdata();

    if ( ! $destination ) {
        status_header( 404 );
        wp_die( 'The selected post has no valid permalink.' );
    }

    if ( wp_safe_redirect( $destination ) ) {
        exit;
    }
} );

WP_Query documents random ordering and a one-result query pattern: WP_Query – Class. The template_redirect hook runs just before WordPress determines which template to load, making it suitable once the requested page is known: template_redirect – Hook.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to expose the endpoint

Using a page slug

  1. In WordPress, go to Pages → Add New.
  2. Create a page with the slug random-post. Its content will not normally be displayed because the callback redirects first.
  3. Link to /random-post/ in a menu, button, or call to action. WordPress will use the site’s actual permalink structure, so use the full URL generated by your site rather than assuming a particular structure.
  4. Test while logged out and in a private browser window, then test again on staging before enabling it on a live site.

Using another condition

Replace is_page( 'random-post' ) with a narrowly defined condition appropriate to your installation. Do not run the callback on every request: an unconditional template_redirect callback can take over feeds, archives, REST requests, and unrelated pages.

#1 Best Overall
Sale
Nulaxy Ergonomic Adjustable Laptop Stand for Desk, Dual Foldable Computer Riser with Advanced Heat-Vent, Heavy-Duty Portable Notebook Holder for Posture Correction, Compatible with Mac 10-16" Laptops
  • Ergonomic Posture Correction: Designed to elevate your laptop to the perfect eye level, this adjustable laptop stand significantly reduces neck, shoulder, and spinal fatigue. Transform your desk into a healthier workstation, ideal for long hours of typing, Zoom meetings, or gaming.
  • Unshakable Dual-Rod Stability: Unlike single-hinge models, our stand features a highly engineered dual-support rod mechanism. It perfectly distributes weight to ensure a 100% wobble-free typing experience, safely supporting heavy-duty devices up to 22 lbs (10kg).
  • Advanced Thermal Cooling Panel: Maximize your device's performance. The unique geometric heat-vent design on the upper panel provides superior airflow compared to standard solid stands. This continuous heat dissipation prevents your laptop from thermal throttling and hardware damage during intensive tasks.
  • Universal 10-16” Compatibility: A versatile computer riser that seamlessly fits all 10 to 16-inch laptops. Broadly compatible with MacBook Pro/Air, Dell XPS, HP, Lenovo, ASUS, Chromebook, and large gaming laptops. The anti-slip silicone pads firmly grip your device and protect it from scratches.
  • Foldable, Portable & Ready to Go: Maximize your productivity anywhere. The dual-foldable design allows the stand to collapse completely flat in seconds. Easily slip it into your backpack or briefcase, making it the ultimate portable office accessory for business trips, cafes, or hybrid work setups.

Control which posts can be selected

The query should describe your intended pool. For example, add 'category_name' => 'tutorials' for one category, or change 'post_type' to a registered custom post type. Keep 'post_status' => 'publish' unless you have a deliberate reason to expose another status. You can also add taxonomy, author, date, or meta-query constraints supported by WP_Query.

If no item meets those constraints, the example returns a 404 response. You could instead redirect to a deliberate, fixed local fallback, but do not pass an empty or unvalidated destination to a redirect function.

Rank #2
Sale
BESIGN LS03 Aluminum Laptop Stand, Ergonomic Detachable Computer Stand, Notebook Riser, Laptop Mount Compatible with Air, Pro, Dell, HP, Lenovo More 10-15.6" Laptops, Silver
  • Broad Compatibility: Besign LS03 Laptop Mount is compatible with all laptops from 10''-15.6'', such as Air 13, Pro 13 / 15 / 2018 / 2017 / 2016, Lenovo ThinkPad, Dell, HP, ASUS, Chromebook, and other notebooks.
  • Ergonomic Design: This LS03 Laptop Stand could elevate your laptop by 6’’ to a perfect viewing level, help you improve your posture and reduce neck and shoulder pain. This laptop stand is super easy to detach and assemble.
  • Stable And Protective: This laptop stand is made of premium Aluminum alloy, it is sturdy, support up to 8.8 lbs(4kg), no worry any wobble at all; the rubber on the holder hands sticks tightly, ensure your laptop stable on the stand and prevent any scratches.
  • Keep Laptop Cool: the open aluminum design provides good ventilation and airflow to prevent your laptop from overheating. It folds flat if you need to store it, create extra space on your desk and keep your desk clean and organized.
  • Easy to Use: thanks to the detachable design, you could assemble it very easily it 3 steps.

Why wp_safe_redirect() and exit matter

wp_safe_redirect() validates that an absolute URL uses an allowed host and defaults to HTTP 302, which is appropriate when a new destination is chosen for each visit. It returns a Boolean value but does not stop PHP execution; WordPress therefore recommends following a successful redirect with exit: wp_safe_redirect() – Function.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

wp_redirect() also requires an explicit exit, but it does not itself validate that the destination is local. Never pass a user-controlled URL to it; see wp_redirect() – Function.

Rank #3
Sale
LOXP Adjustable Laptop Stand, Computer Stand with 360 Rotating Base
  • ✔️[Foldabe & Protable] - Foldable laptop stand for desk & Protable computer stand, It combines the advantages of market brackets, convenient travel laptop stand. Easy to use. Suitable for working at home, office and outdoor, improve comfort.
  • ✔️[360°Rotation] - The computer stand with 360° rotating base, 360° rotation connected with the base is more flexible, the computer stand allows you to rotate the laptop to any angle.
  • ✔️[Stable & Durable] - The Computer stand is made of one-piece fiber metal material, which is more durable and stable than ordinary aluminum alloy computer stands. The upgraded rotating base makes the stand performance more stable, and the non-slip silicone protects the laptop from sliding.Only supports laptops up to 16 inches.
  • ✔️[Ergonmic Desing] - You can freely adjust the height and angle of the laptop stand to keep it at eye level, which helps to reduce the pressure on your body while working. Whether sitting or standing, there is a comfortable angle.
  • ✔️[Wide Compatibility] - Our laptop stand is compatible with all laptops from 10-16 inches, such as MacBook Air/Pro, Google PixelBook, Dell XPS, HP, ASUS, Lenovo ThinkPad, Acer, Chromebook and Microsoft Surface, etc. It is an ideal companion for computer workers.

Choosing between implementation approaches

Approach Selection location Random ordering Best fit
WP_Query callback Server side Directly supported with orderby => 'rand' A simple WordPress redirect with precise post-type or taxonomy rules
Core REST posts collection Client side or another server component Documented orderby choices do not include random ordering Apps that need post lists, filtering, or pagination rather than one redirect
Plugin Depends on the plugin Depends on the plugin Site owners who prefer an administration UI; no plugin is required for this pattern

The REST posts endpoint is documented for collection retrieval and pagination, not a built-in random-post redirect: Posts – REST API Handbook. Its pagination documentation caps per_page at 100 and warns that large queries can affect performance: Pagination – REST API Handbook.

Performance and operational caveats

WordPress’s documentation establishes the query pattern but does not provide a universal speed benchmark for orderby => 'rand'. Database size, traffic, caching, and hosting all affect the result. On a large or heavily visited site, measure this endpoint on the actual installation before relying on it at scale and consider a tailored selection design if measurements show a problem.

Rank #4
Gogoonike Adjustable Laptop Stand for Desk, Metal Laptop Riser Holder
  • 【Adjustable & Ergonomic】:This laptop stand can be adjusted to a comfortable height and angle according to your actual needs, letting you fix posture and reduce your neck fatigue, back pain and eye strain. Very comfortable for working in home, office and outdoor.
  • 【Sturdy & Protective】 :Made of sturdy metal, it can support up to 17.6 lbs (8kg) weight on top; With 2 rubber mats on the hook and anti-skid silicone pads on top & bottom, it can secure your laptop in place and maximum protect your device from scratches and sliding. Moreover, smooth edges will never hurt your hands.
  • 【Heat Dissipation】 :The top of the laptop stand is designed with multiple ventilation holes. The open design offers greater ventilation and more airflow to cool your laptop during operation other than it just lays flat on the table.
  • 【Portable & Foldable】:The foldable design allows you to easily slip it in your backpack. Ideal for people who travel for business a lot.
  • 【Broad Compatibility】:Our desktop book stand is compatible with all laptops from 10-15.6 inches, such as MacBook Air/ Pro, Google Pixelbook, Dell XPS, HP, ASUS, Lenovo ThinkPad, Acer, Chromebook and Microsoft Surface, etc.Be your ideal companion in Home, Office & Outdoor.
  • Keep the eligible pool intentional instead of querying every post type by accident.
  • Use a temporary redirect; the random choice should be made again on a later visit.
  • Verify that caching does not serve one visitor’s redirect response to everyone. Configure page or edge caches to treat the endpoint appropriately.
  • After changing rewrite rules or the page slug, visit Settings → Permalinks and click Save Changes if WordPress needs its rewrite rules refreshed.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failure modes

The endpoint shows the page instead of redirecting

Confirm that the slug in is_page() exactly matches the page, that the code is active, and that no earlier fatal error prevents WordPress from loading it.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Every request redirects

Inspect the route condition. The callback must return for requests that are not your random-post endpoint.

Best Value
Tonmom Adjustable Laptop Stand for Desk, Metal Foldable Laptop Riser
  • ✅【Adjustable & Ergonomic】:This laptop stand can be adjusted to a comfortable height and angle according to your actual needs, letting you fix posture and reduce your neck fatigue, back pain and eye strain. Very comfortable for working in home, office and outdoor.
  • ✅【Sturdy & Protective】 :Made of sturdy metal, it can support up to 17.6 lbs (8kg) weight on top; With 2 rubber mats on the hook and anti-skid silicone pads on top & bottom, it can secure your laptop in place and maximum protect your device from scratches and sliding. Moreover, smooth edges will never hurt your hands.
  • ✅【Heat Dissipation】 :The top of the laptop stand is designed with multiple ventilation holes. The open design offers greater ventilation and more airflow to cool your laptop during operation other than it just lays flat on the table.
  • ✅【Portable & Foldable】:The foldable design allows you to easily slip it in your backpack. Ideal for people who travel for business a lot.
  • ✅【Broad Compatibility】:Our laptop holder is compatible with all laptops from 10-17.3 inches, such as MacBook Air/ Pro, Google Pixelbook, Dell XPS, HP, ASUS, Lenovo ThinkPad, Acer, Chromebook and Microsoft Surface, etc.Be your ideal companion in Home, Office & Outdoor.

A 404 appears

Check that at least one post matches the selected post type, status, category, and other constraints. Also confirm that the selected post has a permalink.

The redirect is rejected

Use a permalink generated by WordPress for the same site and keep wp_safe_redirect(). Do not substitute an unchecked query-string destination.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.