My VS Code Setup for WordPress and PHP, So It Stops Feeling Clunky
A one-time Intelephense + stubs setup that gives WordPress and PHP IntelliSense across projects, plus real core files for Go to Definition.
My VS Code Setup for WordPress and PHP, So It Stops Feeling Clunky
I’ve been working with WordPress for a long time. I started with theme development. Later, I moved into plugin support.
Support work is not the same as building or working on features every day. I helped users with fixes and workarounds, so my PHP and WordPress fundamentals got rusty over time.
Though, I didn’t stop coding. I kept writing JavaScript in my personal time, I stayed up to date with the modern JS stack. Over time, my weak side got weaker, and my strong side got stronger.
I noticed the gap during an interview. The interviewer said I could open the WordPress Codex. I did, and I still felt stuck. That moment made it clear. I needed to get the full picture clear again, and I needed my editor to help more to check source code and reference.
This guide is the setup I use in VS Code with Intelephense. It gives you WordPress and PHP IntelliSense across all projects on your machine with source code. You set it once in user settings.
Overview
Here’s what we’re doing:
- Install WordPress and PHP stub files with Composer (globally).
- Point Intelephense to those stubs.
- Point Intelephense to a local WordPress core folder so “Go to Definition” can open real core files.
What You Get
- Autocomplete for WordPress core functions and classes
- WordPress globals like
$wpdb,$wp_query, and$post - PHP built-in functions like
file_exists()andarray_* - PHP superglobals like
$_GET,$_POST, and$_SERVER - Better navigation for core WordPress files
- A full experiece like PHPStorm
Prerequisites
- Intelephense extension installed
- Composer installed
- A local WordPress codebase on disk (Herd, Valet, or any install you can point to)
Step 1: Install PHP & WordPress Stubs Globally
Install the stub packages globally via Composer:
composer global require php-stubs/wordpress-stubs php-stubs/wordpress-globals
To confirm where Composer installed them on your machine, run:
composer global config vendor-dir --absolute
Your stubs live under:
<global-vendor-dir>/php-stubs/
Step 2: Configure VS Code Global Settings
Now add the stubs path and your WordPress core path to VS Code user settings.
Option A: Edit settings.json directly
- Open VS Code Settings (CMD/Ctrl + ,)
- Click the “Open Settings (JSON)” icon in the top-right corner
- Add this configuration
{
"intelephense.environment.phpVersion": "8.2",
"intelephense.environment.includePaths": [
"${env:HOME}/path/to/your/wordpress",
"/absolute/path/to/your/global/composer/vendor/php-stubs"
],
"intelephense.stubs": [
"apache",
"bcmath",
"bz2",
"calendar",
"Core",
"ctype",
"curl",
"date",
"dom",
"exif",
"fileinfo",
"filter",
"ftp",
"gd",
"gettext",
"hash",
"iconv",
"imagick",
"imap",
"intl",
"json",
"libxml",
"mbstring",
"mysqli",
"mysqlnd",
"openssl",
"pcntl",
"pcre",
"PDO",
"pdo_mysql",
"Phar",
"posix",
"redis",
"Reflection",
"session",
"SimpleXML",
"soap",
"sockets",
"sodium",
"SPL",
"standard",
"tokenizer",
"xml",
"xmlreader",
"xmlrpc",
"xmlwriter",
"zip",
"zlib"
]
}
Important: Update the WordPress path
Replace ${env:HOME}/path/to/your/wordpress with your WordPress core path:
If using Laravel Herd (macOS):
"${env:HOME}/Herd/wordpress"
If using Laravel Valet:
"${env:HOME}/.config/valet"
Custom path:
"/absolute/path/to/your/wp-installation"
Important: Update the stubs path
Run this and copy the result:
composer global config vendor-dir --absolute
Then set the stubs path to:
<global-vendor-dir>/php-stubs
If the path is inside your home folder, you can replace /Users/yourname with ${env:HOME}.
Step 3: Reload VS Code
After updating the settings, reload VS Code:
- Press
CMD+Shift+P(macOS) orCtrl+Shift+P(Windows/Linux) - Type “Reload Window”
- Press Enter
Step 4: Verify IntelliSense is Working
Open any PHP file and test:
- Type
$_and check for PHP superglobals - Type
file_and check for PHP functions - Type
wp_and check for WordPress functions - Type
$wpdband check for methods on thewpdbclass - Type
new WP_and check for WordPress classes
How It Works
Include Paths
intelephense.environment.includePaths tells Intelephense where to look for PHP files outside your project.
We add two locations:
- Your WordPress core folder. This helps with “Go to Definition”.
- The
php-stubsfolder. This helps with autocomplete and signatures.
Stubs
intelephense.stubs is for PHP extension stubs bundled with Intelephense. This is how you get signatures for things like curl, mbstring, and mysqli.
Environment Variables
Using ${env:HOME} instead of hardcoded paths (like /Users/username/) makes your configuration portable across different machines and users.
Setting Up on Multiple Devices
If you use VS Code Settings Sync, your settings can carry over. On a new device, you still need to install the stubs again with Composer.
You can also use a small setup script.
Create a setup script to run on new devices:
setup-php-stubs.sh
#!/bin/bash
echo "Setting up PHP and WordPress stubs globally..."
# Install stubs globally via composer
composer global require php-stubs/wordpress-stubs php-stubs/wordpress-globals
# Get global composer vendor path
VENDOR_PATH=$(composer global config vendor-dir --absolute)
STUBS_PATH="$VENDOR_PATH/php-stubs"
echo "Stubs installed to: $STUBS_PATH"
echo ""
echo "Add this to your VS Code settings.json:"
echo ""
echo '"intelephense.environment.includePaths": ['
echo ' "${env:HOME}/Herd/wordpress",'
echo " \"$STUBS_PATH\""
echo "],"
echo ""
echo "Done! Reload VS Code to apply changes."
Make it executable and run:
chmod +x setup-php-stubs.sh
./setup-php-stubs.sh
Troubleshooting
IntelliSense not working after setup
-
Reload VS Code window (CMD+Shift+P → “Reload Window”)
-
Check the stubs are installed:
VENDOR_DIR=$(composer global config vendor-dir --absolute) ls "$VENDOR_DIR/php-stubs/"You should see folders like
wordpress-stubsandwordpress-globals. -
Verify your WordPress path is correct:
- Make sure the path exists
- Make sure it contains WordPress core files (wp-includes, wp-admin, etc.)
Some PHP functions show as undefined
Make sure you’ve added the necessary extension stubs in the intelephense.stubs array. The list provided includes all common PHP extensions.
Slow performance
If IntelliSense feels slow, you can:
-
Increase the file size limit (default is 1MB):
"intelephense.files.maxSize": 5000000 -
Exclude more directories from indexing:
"intelephense.files.exclude": [ "**/node_modules/**", "**/vendor/**/{Test,test,Tests,tests}/**", "**/storage/**", "**/cache/**" ]
Optional: PHP editor settings
If you want, add these PHP-specific settings:
{
"[php]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client",
"editor.suggest.insertMode": "replace",
"editor.tabSize": 4
},
"intelephense.completion.insertUseDeclaration": true,
"intelephense.compatibility.correctForBaseClass": true
}
Complete Example Configuration
Here’s a full example you can adapt:
{
"intelephense.environment.phpVersion": "8.2",
"intelephense.environment.includePaths": [
"${env:HOME}/Herd/wordpress",
"/absolute/path/to/your/global/composer/vendor/php-stubs"
],
"intelephense.stubs": [
"apache",
"bcmath",
"bz2",
"calendar",
"Core",
"ctype",
"curl",
"date",
"dom",
"exif",
"fileinfo",
"filter",
"ftp",
"gd",
"gettext",
"hash",
"iconv",
"imagick",
"imap",
"intl",
"json",
"libxml",
"mbstring",
"mysqli",
"mysqlnd",
"openssl",
"pcntl",
"pcre",
"PDO",
"pdo_mysql",
"Phar",
"posix",
"redis",
"Reflection",
"session",
"SimpleXML",
"soap",
"sockets",
"sodium",
"SPL",
"standard",
"tokenizer",
"xml",
"xmlreader",
"xmlrpc",
"xmlwriter",
"zip",
"zlib"
],
"[php]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client",
"editor.suggest.insertMode": "replace",
"editor.tabSize": 4
},
"intelephense.completion.insertUseDeclaration": true,
"intelephense.compatibility.correctForBaseClass": true,
"intelephense.files.exclude": [
"**/.git/**",
"**/.svn/**",
"**/.hg/**",
"**/CVS/**",
"**/.DS_Store/**",
"**/node_modules/**",
"**/bower_components/**",
"**/vendor/**/{Test,test,Tests,tests}/**"
],
"intelephense.files.maxSize": 1000000
}
Summary
This setup gives you:
- One global VS Code config for WordPress and PHP
- Faster navigation in core code
- Better autocomplete from stubs
That’s it.
Links: