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 created a page in wordpress and i tried to access the current logged in user via wp_get_current_user() and am getting error "function undefined". please how do I make this function available in my page.

share|improve this question
is this a php page you created? – Bainternet Jul 13 '11 at 6:49
Yes it is a php page – joe Jul 13 '11 at 19:38
try adding require('/the/path/to/your/wp-blog-header.php'); at the top of your PHP page – Bainternet Jul 13 '11 at 19:49
thanks Bainternet but I have added the require and am getting the error "cannot coonect to database" this is the code below: – joe Jul 14 '11 at 5:32
<?php require('/wordpress/wp-blog-header.php'); $current_user = wp_get_current_user(); $current_user->set_role(rocky2); ?> – joe Jul 14 '11 at 5:32

You can use following..

global $current_user;

Than you can access everything as


Here is explanation...

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.