PHPCS WPCS setup in VS Code on Windows gives WordPress developers fast feedback on coding-standard issues while they write PHP. This step-by-step guide shows how to install PHP CLI and Composer, add WordPress Coding Standards to a project, configure the VS Code PHPCS extension, create a reusable ruleset, and run checks or automatic fixes safely.
Table of Contents
How to Set Up PHPCS & WPCS in VS Code on Windows
Set up PHP_CodeSniffer (PHPCS), WordPress Coding Standards (WPCS), and Visual Studio Code on Windows so you can detect WordPress coding-standard violations while you work. This guide covers the PHP command-line runtime, Composer installation, project-local and global WPCS setup, VS Code configuration, a reusable phpcs.xml.dist ruleset, and commands for checking and fixing your code.
1. Install PHP for command-line tools
PHPCS and Composer run through PHP CLI. First check whether PHP is already available in your terminal. Open a new Command Prompt or PowerShell window and run:
php -v
If PHP prints a version, the CLI executable is available. If Windows reports that the command is not recognized, install a standalone PHP build and add its folder to your Windows Path. Use a PHP version compatible with your project and the Composer packages you plan to install; do not choose an old PHP release just because a tutorial lists it.
Important: The PHP version used by your local web server and the PHP executable used by Command Prompt can be different. Local, XAMPP, or another development stack may bundle its own PHP. Check
php -vandwhere.exe phpto see which CLI executable your terminal is actually using.
1.1 Download and extract PHP for Windows
- Open the official PHP for Windows downloads page.
- Choose an x64 build that is compatible with your project. For command-line use, the Non Thread Safe (NTS) build is generally suitable. Thread Safe (TS) builds are primarily intended for PHP loaded as an Apache module.
- Download the ZIP package, extract it to a stable folder such as
C:\php, and keep the folder path consistent. If you maintain projects that require different PHP versions, use separate versioned folders rather than overwriting one installation. - Follow the PHP Windows instructions for any required Visual C++ runtime and PHP configuration. Copy
php.ini-developmenttophp.iniif you need to configure CLI extensions.
1.2 Add PHP to the Windows PATH
Adding the PHP folder to Path lets Windows find php.exe when you run PHP commands from any directory.
- Press the Windows key, search for Environment Variables, and open Edit the system environment variables.
- Select Environment Variables, then choose the
Pathvariable under your user variables and click Edit. - Select New and add the folder containing
php.exe, for exampleC:\php. Add the folder, not the path to the executable itself. - Confirm the dialogs with OK. Close and reopen Command Prompt or PowerShell so the updated PATH is loaded.
- Run
where.exe phpandphp -v. If multiple PHP paths are listed, Windows uses the first matching executable in PATH.
Close existing terminals, open a new Command Prompt, and verify the executable and version:
php -v
2. Install Composer on Windows
Composer manages PHP dependencies. WPCS is installed through Composer, which also resolves the compatible PHPCS and ruleset dependencies.
2.1 Download and run Composer-Setup.exe
- Open the official Composer download page.
- Download and run
Composer-Setup.exefor Windows. - When prompted to select the command-line PHP executable, browse to the
php.exeyou verified in Step 1. - Complete the installer. If it offers to update the Windows PATH, allow it to do so.
- Close and reopen your terminal, then run
composer --version.
composer --version
composer diagnose
- If
composeris not recognized, rerun the installer or add Composer’s executable directory to PATH, then open a new terminal. - If Composer uses the wrong PHP version, check the PHP path selected in the Composer installer and compare it with
where.exe php.
where.exe php
php -v
where.exe composer
composer --version
2.2 Verify the Composer installation
- Close every open Command Prompt or PowerShell window so Windows reloads the updated PATH.
- Open a new terminal and run
composer --versionto confirm Composer is available. - Run
composer diagnoseto check the Composer environment and identify common configuration problems. - If Composer reports that PHP cannot be found, rerun Composer Setup and select the correct
php.exepath.
You can also confirm which PHP executable is resolved by your terminal:
where.exe php
php -v
composer --version
composer diagnose
3. Install PHPCS WPCS and WordPress Coding Standards
PHPCS checks PHP files against a selected coding standard. WPCS adds the WordPress-specific rules used to check formatting, documentation, and common WordPress coding practices. The current WPCS 3.x installation is Composer-based and uses the Composer PHPCS installer plugin to register the standards.
3.1 Recommended: install WPCS inside your project
For a WordPress plugin or theme, a project-local installation is usually the most predictable option. It keeps the PHPCS and WPCS versions with the repository, so every developer and CI job can use the same toolchain. Open a terminal in your plugin or theme root and run:
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer require --dev wp-coding-standards/wpcs:"^3.0"
Composer installs the required PHPCS dependency and registers the WPCS rulesets. Verify the available standards from the project root:
vendor\bin\phpcs.bat --version
vendor\bin\phpcs.bat -i
3.2 Alternative: install WPCS globally
A global installation is convenient when you want to run PHPCS across multiple projects without adding development dependencies to each repository. Run these commands in a terminal:
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require --dev wp-coding-standards/wpcs:"^3.0"
Find Composer’s actual global binary directory instead of assuming its location:
composer global config bin-dir --absolute
Add the returned directory to your Windows user Path. Open a new terminal and verify with phpcs --version and phpcs -i. The available standards should include WordPress, WordPress-Core, WordPress-Docs, and WordPress-Extra. Use the project-local commands when the repository has its own Composer installation.
4. Configure PHPCS in Visual Studio Code
VS Code’s built-in PHP validation checks PHP syntax. PHPCS is a separate tool that checks coding standards. You need a PHPCS extension to display WPCS diagnostics in the editor.
4.1 Install the PHPCS extension
Open Extensions with Ctrl + Shift + X, search for phpcs, and install PHP CodeSniffer by shevaua. This guide uses that extension for linting. Avoid configuring multiple PHPCS extensions to lint the same files at the same time, because duplicate diagnostics and formatters can conflict.
- Open your WordPress plugin or theme folder as the VS Code workspace.
- If you installed PHPCS locally with Composer, use the project-local executable so the editor uses the same version as your terminal.
- If automatic detection does not work, set the executable path explicitly in workspace settings as shown below.
4.2 Configure settings.json
Open the Command Palette with Ctrl + Shift + P, select Preferences: Open Workspace Settings (JSON), and add the settings below. Change the PHP path to match your installation. The PHPCS extension should use the project-local executable when it is available.
{
"php.validate.executablePath": "C:/php/php.exe",
"phpcs.enable": true,
"phpcs.executablePath": "vendor/bin/phpcs.bat",
"phpcs.standard": "WordPress"
}
5. Troubleshoot common PHPCS and WPCS errors
If you run into issues during the setup, check these common fixes:
- PHP is not recognized: Run
where.exe php. If no path is returned, add the folder containingphp.exeto Windows PATH, then open a new terminal and restart VS Code. - Composer uses the wrong PHP version: Compare
php -vwith the PHP executable selected by Composer Setup. Correct the selected path and reopen the terminal. - WPCS is not listed by PHPCS: Run Composer from the same project directory where you installed WPCS. Check that the Composer PHPCS installer plugin is allowed, then run
composer installor repeat the project installation commands. - VS Code cannot find PHPCS: Confirm that
vendor/bin/phpcs.batexists in the workspace and thatphpcs.executablePathpoints to it. If you use a global installation, point the extension to the globalphpcs.batinstead. - VS Code shows no diagnostics: Check that PHPCS linting is enabled, the selected standard is
WordPress, and the file is inside the opened workspace. Run PHPCS in the terminal first to separate extension problems from PHPCS configuration problems. - Composer reports a PHP or extension requirement: Check the PHP version used by Composer and enable the required PHP extensions in the CLI
php.ini. Do not use--ignore-platform-reqsas a permanent fix.
6. Create a project-level phpcs.xml.dist ruleset
A project ruleset makes the coding standard repeatable and avoids relying on editor-only settings. In the root of your plugin or theme, create a file named phpcs.xml.dist. This example uses the WordPress standard, scans PHP files in the project, and excludes Composer and frontend dependency folders.
<?xml version="1.0"?>
<ruleset name="Project WordPress Coding Standards">
<description>PHPCS rules for this WordPress project.</description>
<rule ref="WordPress" />
<file>.</file>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<arg name="basepath" value="." />
<arg name="colors" />
<arg value="sp" />
</ruleset>
PHPCS automatically looks for a phpcs.xml, phpcs.xml.dist, .phpcs.xml, or .phpcs.xml.dist ruleset in the current directory and its parent directories. If your project already has a custom ruleset, review it before replacing it. You can add or exclude paths according to your plugin’s actual folder structure.
7. Run PHPCS and fix coding-standard violations
Run these commands from the plugin or theme root. The first command checks the project using the ruleset. The second command reports violations with their sniff codes, which helps you identify the relevant rule.
vendor\bin\phpcs.bat .
vendor\bin\phpcs.bat -s .
PHPCBF can automatically fix a subset of PHPCS violations. Run it only after reviewing your working tree and creating a commit or backup. Automatic fixes can change code formatting, so inspect the diff and run PHPCS again afterward.
vendor\bin\phpcbf.bat .
vendor\bin\phpcs.bat -s .
Not every WordPress coding-standard warning can be fixed automatically. Review remaining messages manually, especially warnings involving escaping, sanitization, nonces, capability checks, database queries, and internationalization. A clean PHPCS report is a coding-standard check; it is not a substitute for security review or functional testing.
8. Verify the setup in VS Code
- Open a PHP file inside the WordPress plugin or theme workspace.
- Introduce a harmless formatting violation in a temporary test file and save it.
- Confirm that the PHPCS extension displays a diagnostic and identifies the WordPress sniff.
- Run the project-local PHPCS command in the terminal and confirm that it reports the same issue.
- Remove the temporary test file or revert the test change, then run PHPCS on the project again.
9. Keep PHPCS consistent across your team
Commit composer.json, composer.lock, and phpcs.xml.dist to version control so the team and continuous-integration environment use the same dependencies and rules. Keep PHPCS and WPCS in development dependencies; production WordPress sites do not need these developer tools installed.
When updating WPCS, review the changelog and run the full check again. New rules or changed sniff behavior can reveal issues that were not reported by the previous version. For team projects, run the same Composer install and PHPCS command in CI so coding-standard checks do not depend only on an individual developer’s VS Code setup.
