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';
}
?>
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';
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.