Visual Studio Code highlighting WordPress function names. Visual Studio Code highlighting WordPress function names.

Why is VS Code With PHP Intelephense Highlighting All WordPress Function Names?

Understanding VS Code and WordPress Integration

One of the challenges you might face while using Visual Studio (VS) Code for WordPress development is receiving full Intellisense support (autocomplete functionality, among others) for WordPress functions. To resolve this concern and enhance the development experience, we need to configure the VS Code settings correctly. Below are a couple of straightforward approaches.

Method 1: Editing the VS Code Settings File

The first method involves manually adding ‘WordPress’ to the intelephense.stubs array setting in your VS Code settings file. This array stores information about all the different types of code stubs that VS Code should recognize, including WordPress code.

Here’s how to do it.

In your VS Code settings file, which is typically named settings.json, locate the "intelephense.stubs" line. It should have an array of stubs, or samples of code that the editor will recognize, listed. You’ll want to include “wordpress” at the end of this array, so it becomes part of the editor’s recognized code stubs.

For instance, your settings.json might look like this after the addition:

{

“intelephense.files.maxSize”: 3000000,

“intelephense.stubs”: [

/ …other stubs here… /

“zlib”,

“wordpress”

]

}

Remember to save the changes and close the file when you’re done.

Do keep in mind that this method works well if you’re comfortable with directly editing the settings file.

Method 2: Using the Extensions Bar in VS Code

Another approach is to use the Extensions bar feature in VS Code. This is a more beginner-friendly method, especially if you’re not comfortable editing the VS Code settings file directly. Here are the steps:

  1. Press Ctrl+Shift+X to open the Extensions bar on the left side of the VS Code screen.
  2. Search for PHP Intelephense in the search bar.
  3. Once you find it, click on the settings icon of this extension and choose ‘Extension Settings’.
  4. Scroll down to find the list of ‘Stubs.’
  5. Click on ‘Add Item’ and then choose ‘wordpress’ from the list.
  6. Save the changes.

If the changes don’t take immediate effect, try closing and reopening VS Code.

It’s important to note that while both methods allow VS Code to recognize built-in WordPress functions and provide Intellisense for them, it won’t recognize functions from installed WordPress plugins.

By following these steps, you can enhance Visual Studio Code’s understanding of WordPress, and consequently, streamline your coding experience. Happy developing!

Some additional references you can check out for more details are the discussions on GitHub about including WordPress stubs in Intelephense and the better ways to get WordPress Intellisense.