Problem accessing wp-load.php

I’m writing a standalone script for WordPress so I can display things like the username on a page outside of WordPress.

My method so far is to try to include or require wp-load.php in my script directory. I’ve tried

chdir ( ".." );
include "wp-load.php";

as well as absolute paths to the web root where WordPress is located for both the chdir and the include. I don’t get any errors but wp_get_current_user() always returns empty.

If I move my script up a level to the same folder with WordPress it works fine. How can I include wp-load.php and keep all of the files in my subfolder?

EDIT: file structure

  • public_html (wordpress is installed here so wp-load.php is also here)
    • myScript (directory)
      • script.php
      • This is where I try to use chdir ( “..” ) or include ( “../wp-load.php” ) without success

2 Answers
2

try this i hope this work.

$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );    
require_once( $parse_uri[0] . 'wp-load.php' );

Leave a Comment