WordPress.org

Ready to get started?Download WordPress

Forums

WP login on page outside WP (4 posts)

  1. graemep
    Member
    Posted 8 years ago #

    I have a page outside WordPress that displays some stuff from WP.

    I would like to restrict access to logged in users. Ideally I would like to return a 404 to anyone else. Is this possible?

  2. Kafkaesqui

    Posted 8 years ago #

    Yep. Just after where wp-blog-header.php is included (you are doing this at the start of the document, right?), add a bit of PHP to return a 404 to non-logged-in visitors:

    <?php
    include('./wp-blog-header.php');

    global $user_login;
    if(!$user_login) {
    header("HTTP/1.0 404 Not Found");
    exit;
    }
    ?>

  3. graemep
    Member
    Posted 8 years ago #


  4. graemep
    Member
    Posted 8 years ago #

    Thanks Kafkaesqui, done in seconds and working fine.

Topic Closed

This topic has been closed to new replies.

About this Topic