WordPress is_user_logged_in restriction

I’m trying to have a page outside of WordPress use the is_user_logged_in function to determine if they can view some data or not. I am definitely logged in and the paths to the WordPress files are correct. Anyone have any thoughts why I can’t see the data?

    <?php
    error_reporting(E_ALL);

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

    if(is_user_logged_in()) {
            //Do Something
    } else {
            echo 'Not logged in';
    }
    ?>

Related posts

Leave a Reply

1 comment

  1. I used require instead of include and your code is perfect now.

    <?php
    error_reporting(E_ALL);
    
    require(dirname(__FILE__) . '/wp-load.php' );
    // include('/wp-blog-header.php');
    
    if(is_user_logged_in()) {
            //Do Something
        echo "LoggedIN";
    } else {
            echo 'Not logged in';
    }
    ?>