I want to somehow use this function on a non-wordpress page :
<?php
if (is_user_logged_in()){
echo "Welcome, registered user!";
}
else {
echo "Welcome, visitor!";
};
?>
Is there any way to do this? I was told it is possible if I include my wp-header.php in the Non-wordpress page, but I do not want to do this. Any other methods?
You don't need to include the admin-header.php file. Just include this file:
wp-includes/pluggable.php
This file contains definition of is_current_logged_in() as well as many other user data helpers such as wp_set_current_user(), wp_get_current_user() etc.
Including wp-load.php is the best way to go. There are loads of ways around this, but I use something similar to the following:
It's a bit of a hack and if you actually know the location of the wp-load.php file, then you can just use that in the require_once() function.
Put that at the top of your file and you'll be able to use all of WordPress' functions in your non-wordpress page.
You have to load the Wordpress Core into your current script. You can do it like this:
You have to use the Wordpress header because that function is in the core. The only other option is to write your own function with the same name, using the same database of users.