I link from WP to a non-wp page. How can I find the username of the person that logged into wp? This doesn’t work.
<?php
require_once("../members/wordpress/wp-load.php");
if(is_user_logged_in())
{
echo '<br />User Logged in ok<br />';
echo 'User ID is: '.$user_ID.'<br />';
echo 'User login is: '.$current_user->user_login.'<br />';
}
else
echo 'No user is logged in<br/>';
?>
Try
Documentation states that it is a wrapper of get_currentuserinfo().
So, try this;
If it does not work since you are on a non-wp page. Try replacing wp_get_current_user() with get_currentuserinfo().
Your non-wp page is not in WP folder, so it won’t have access to WP cookie. If you want WP cookie to be seen by php script located outside of your WP folder, need to define
COOKIEPATH
to point to common parent folder of your php script & your wp folder, or just point it to root folder.Put the following line in your wp-config.php:
PS: Also your non-wp page should be served from the same domain as WP.
This is working well.
In WordPress I saved a cookie. Then in a non-wordpress page, before the
DOCTYPE line, I placed this code: