If you’re developing WordPress themes and plugins in Visual Studio Code using PHP Intelephense, you’ve probably run into an issue: the extension doesn’t recognize functions from popular plugins like WooCommerce, ACF, Gravity Forms, Elementor, and others by default.
This guide will show you how to add support for these plugins in Intelephense using stub files, so you can enjoy proper autocompletion, function signatures, and fewer false-positive errors.
What Are Stubs?
Stub files are simplified versions of PHP code that define function signatures, classes, and constants. They’re not meant to run but help IDEs like Intelephense understand the available codebase, especially for large plugins and frameworks that are not loaded in your project by default.
Step 1: Install Intelephense in VS Code
If you haven’t already:
- Open VS Code.
- Go to Extensions (
Ctrl+Shift+X
). - Search for
Intelephense
and install “PHP Intelephense” by Ben Mewburn.
Step 2: Download Stub Files
Download the following stubs for WordPress core and popular plugins you use:
Plugin | Stub Repository |
---|---|
WordPress Core | php-stubs/wordpress-stubs |
WooCommerce | php-stubs/woocommerce-stubs |
ACF Pro | php-stubs/acf-pro-stubs |
Gravity Forms | php-stubs/gravity-forms-stubs |
Elementor | arifpavel/elementor-stubs |
Yoast SEO | php-stubs/wordpress-seo-stubs |
Polylang Pro | php-stubs/polylang-pro-stubs |
WP-CLI | php-stubs/wp-cli-stubs |
Genesis Framework | php-stubs/genesis-stubs |
WordPress Globals | php-stubs/wordpress-globals |
Clone or download the .php
files from each repository.
Step 3: Add Stub Files to Intelephense (Two Methods)
To enable IntelliSense for plugins like WooCommerce, ACF, Gravity Forms, and others, we need to let Intelephense know about their function definitions. This can be done in two ways:
Method 1: Use intelephense.environment.includePaths (Recommended)
This is the official and update-safe method.
- Place your downloaded
.php
stub files in a folder, such as:C:\wamp64\www\php-stubs\
Your folder structure should look like:
C:\wamp64\www\php-stubs\ ├── woocommerce-stubs.php ├── acf-pro-stubs.php ├── gravity-forms-stubs.php └── ...
- Open your project’s VS Code settings (
.vscode/settings.json
) and add this:{ "intelephense.environment.includePaths": [ "C:/wamp64/www/php-stubs" ] }
Make sure you’re using double backslashes (
\\
) if you edit this in Windows-style paths, or forward slashes (/
) like shown above. - Save and close all files. Then:
- Run “Intelephense: Index Workspace” from the command palette (
Ctrl+Shift+P
) - Restart VS Code
- Run “Intelephense: Index Workspace” from the command palette (
If That Doesn’t Work…
In some cases (as happened to me), Intelephense doesn’t properly load the .php stub files via includePaths. In that case, you can use the alternative method below, which works reliably but needs to be repeated after each extension update.
Method 2: Copy Stub Files to the Intelephense Extension Folder
- Open the following directory in your file explorer:
C:\Users\<YourUsername>\.vscode\extensions\bmewburn.vscode-intelephense-client-<version>\node_modules\intelephense\lib\stub\wordpress
Replace
<YourUsername>
and<version>
with your actual username and the installed Intelephense version (e.g.,1.14.4
). - Copy all downloaded
.php
stub files into thewordpress
folder. - Overwrite any existing files if prompted.
Step 4: Restart VS Code
After copying the stub files:
- Restart VS Code completely.
- Open any file that uses functions like
get_field()
,wc_get_product()
, orthe_content()
. - Check that Intelephense now provides autocomplete and no longer shows “undefined function” errors.
Important Tip
VS Code extension updates can overwrite this folder, removing your custom stubs if that’s what worked for you. Keep a backup or consider writing a small script to automate copying the stubs back after updates.
Result
Once set up correctly, Intelephense will fully recognize:
- WordPress core functions
- WooCommerce, ACF, Gravity Forms, Elementor, and more
- Custom post types and plugin-specific hooks
This results in better IntelliSense, more reliable error checking, and an overall smoother coding experience in VS Code.
Wrapping Up
Using stub files with Intelephense is a powerful way to improve your WordPress development workflow in VS Code. With the right stubs in place, you get full code intelligence for the most-used plugins without needing to load their full source code into your workspace.
Feel free to bookmark the stub repositories or fork them to keep your own custom versions up to date!
Muhammad Zohaib