Disable Direct Access to A WordPress Page

Share Now

Share on facebook
Share on pinterest
Share on twitter
Share on linkedin
Share on email
<?php
add_action('template_redirect', function () {
    //Page you want to redirect
    if (!is_page(ADD_YOUR_PAGE_ID)) {
        return;
    }
    if (wp_get_referer() == 'ENTER_THE_URL_FROM_WHERE_IT_SHOULD_BE_ACCESSIBLE') {
        return;
    }
    //Where You Want To Redirect
    wp_redirect(get_permalink(ADD_YOUR_PAGE_ID));
    exit;
});
?>
Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert