Home / eCommerce / Allowed Referrer Page
Duplicate Snippet

Embed Snippet on Your Site

Allowed Referrer Page

Serve the page only when the condition is met, otherwise redirect to home page, eg. Thank you page.

Code Preview
php
<?php
// Allowed Referrer Page / Kiri Vadivelu / 2026
add_action('template_redirect', function() {
    // ID of the page to protect eg. Thank You page
    if (!is_page(123)) {
        return;
    }
    // URL of the allowed referring page
    if (wp_get_referer() === 'https://yoursite.com/form-page/') {
        return;
    }
    // Redirect unauthorized direct access
    wp_redirect(get_home_url());
    exit;
});   

Comments

Add a Comment