简体   繁体   中英

Phpstorm doesn't know how to run Wordpress

I've tried all I could found here and googling. Include paths, external libraries, interpreter settings...

Whenever I try to run my theme's index.php file:

C:\XAMPP\php\php.exe "C:\path\to\project\wp-content\themes\MYTHEME\index.php"

Fatal error: Call to undefined function get_header() in C:\path\to\project\wp-content\themes\MYTHEME\index.php on line 1

Process finished with exit code 255

So yes on line 1 I'm just calling my header.

Turns out it's trying to run index.php like a standalone file, but ignoring the whole Wordpress instalation (that I have included from different angles). Certainly it nows where get_header() is because I can control click it and it'll bring me to the file it's declared in, no problems.

It correctly detects XAMP's PHP interpreter too.

It also works well if I just visit the site typing my localhost URL in the browser. It just won't work through Phpstorm.

You are directly calling theme's index file which is not correct way, as your theme must be using some default functions of WordPress, like get_header() in this case.

So you need to make sure wp-load.php is loaded to make all WP functions available to use. You have two way for that:

1) Call root index.php so everything will be loaded by default.

2) Call theme's index.php but add Below code in that:

if(!function_exists('get_header')) {
    require_once( '/wp-load.php' );
}

However this is not good way :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM