WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a php page called "test.php" and uploaded this file to the root folder of my wordpress installation.

This file contains only this:

<?php if ( is_user_logged_in() ) { blah..... }  ?>

I need to check if user is logged in and if so, get some details.

So what I need to know is what wp file(s) I need to include in my php file to be able to get the results of this function and also I prob need to check on an id, username.

share|improve this question

Adding the following code to the top of the PHP file will give you access to the Wordpress functions and global variables.

<?php include_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php' );

You should then be able to run normal Wordpress functions to determine whether or not the user is logged in:

global $user_ID; 
if ($user_ID) {
    // Do Something 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.