Written from the trenches by a WordPress‑first PHP dev, PHPCS/WPCS evangelist, and chronic code‑quality nerd.
Introduction
As a professional WordPress developer, adhering to a consistent coding standard is crucial. It keeps your code clean, readable, and ensures compatibility across teams and projects. That’s where PHP_CodeSniffer (PHPCS) and WordPress Coding Standards (WPCS) come into play.
In this guide, I’ll walk you through the step-by-step installation of PHP_CodeSniffer and WPCS on Windows, setting them up system-wide using Composer, and configuring your project to use them effectively. This is a beginner-friendly, complete guide, so even if this is your first time, don’t worry—I’ve got you.
Why I Can’t Live Without PHPCS + WPCS
When I first started writing WordPress plugins I sprinkled require_once
everywhere and prayed my code passed review. Then I discovered PHP CodeSniffer (PHPCS) and the WordPress Coding Standards (WPCS):
Instant feedback – It flags bad escaping, snake‑case issues, mixed tabs/spaces, etc.
Auto‑fixer – Most whitespace and array‑syntax errors disappear with one command.
Consistent code – Clients, collaborators, and the WordPress.org review team see a familiar style.
If you develop themes or plugins, linting your code is the fastest way to avoid hidden bugs and meet the official standards.
Prerequisites
What | Why you need it | My detailed how‑to |
---|---|---|
System‑wide PHP (≥ 7.4) | PHPCS/WPCS run under PHP | Install PHP on Windows (Complete Guide 2025) |
Composer (global) | Pulls PHPCS + WPCS + plugins | Global Composer Setup on Windows (Step‑by‑Step) |
Already ticked these two boxes? Perfect—jump in.
Step-by-Step Guide to Install PHPCS on Windows
Step 1: Install PHP_CodeSniffer Globally
Open PowerShell or Cmd:
composer global require "squizlabs/php_codesniffer=*"
What the command does
composer global
→ installs packages into%APPDATA%\Composer\vendor
.require
→ adds the package to the globalcomposer.json
."squizlabs/php_codesniffer=*"
→ pull the latest PHPCS release (major + minor).
Uh‑oh, ZIP Error?
ERROR: Failed to download squizlabs/php_codesniffer from dist:
The zip extension and unzip/7z commands are both missing, skipping.
The zip PHP extension is disabled. Here’s my 60‑second fix:
Locate your active
php.ini
(runphp --ini
if unsure).Search for
;extension=zip
and uncomment it:bashextension=zip
- Save, close all terminals, reopen, and repeat the install command:bash
composer global require "squizlabs/php_codesniffer=*"
Verify PHPCS
phpcs --version
Example output:
PHP_CodeSniffer version 3.9.2 (stable) by Squiz and PHPCSStandards
Step 2: Add Composer's Global Bin to PATH
To run phpcs
and phpcbf
from anywhere, add the Composer bin directory to your system environment variables.
Steps:
Press
Win + S
and search “Environment Variables”.Click on Environment Variables under System Properties.
Under User variables, find
Path
→ Click Edit.Add:
bash%APPDATA%\Composer\vendor\bin
Click OK, then restart your terminal or VS Code.
Step-by-Step Guide to Install WordPress Coding Standards (WPCS)
Step 1: Install WordPress Coding Standards
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require --dev wp-coding-standards/wpcs:"^3.0"
phpcs -i
The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz,
Zend, Modernize, NormalizedArrays, Universal, PHPCSUtils,
WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra
Step 2: Set Up Project-Level Configuration
Open your project folder in VS Code.
Create a file named
phpcs.xml
in the root directory.
Paste the following content:
<?xml version="1.0"?>
<ruleset name="Elementrix – WP Standard">
<rule ref="WordPress"/>
<file>.</file>
<exclude-pattern>vendor/*</exclude-pattern>
</ruleset>
<rule ref="WordPress"/>
→ use the full WP ruleset.<file>.</file>
→ scan the current directory (required).<exclude-pattern>
→ skip Composer/vendor and any third‑party code.
Step 3: Set WordPress as Default Coding Standard
To set WordPress as the default standard globally:
phpcs --config-set default_standard WordPress
Now verify:
phpcs --config-show | findstr default_standard
Unset (if ever needed):
phpcs --config-delete default_standard
Step 4: To Validate Project Files Run PHPCS in VS Code (or any terminal)
phpcs
phpcs includes/example.php
<file>.</file>
in phpcs.xml
you’ll get:ERROR: You must supply at least one file or directory to process.
phpcs
or phpcs includes/example.php
Typical outputFILE: controls/class-test-control.php
--------------------------------------------------------------------------------
FOUND 8 ERRORS AND 1 WARNING AFFECTING 8 LINES
...
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
phpcbf
phpcbf includes/example.php
Frequently Asked Questions (FAQs)
1. How do I update PHP_CodeSniffer (PHPCS) to the latest version?
To update PHPCS globally via Composer, run:
composer global update squizlabs/php_codesniffer
This will fetch the latest compatible version based on your PHP version.
2. How do I update the WordPress Coding Standards (WPCS)?
To update WPCS globally:
composer global update wp-coding-standards/wpcs
If you also want to update related plugins like dealerdirect/phpcodesniffer-composer-installer
, run:
composer global update
3. What versions of PHP are supported by PHPCS and WPCS?
Both tools require PHP ≥ 7.4 on Windows. I personally recommend PHP 8.2 or newer to stay aligned with current WordPress core development.
4. Composer says “running scripts is disabled on this system.” How do I fix it?
Set‑ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
This lets Composer run its post‑install scripts without permanently lowering your machine’s security.5. How do I completely remove PHPCS and WPCS if needed?
To remove PHPCS:
composer global remove squizlabs/php_codesniffer
To remove WPCS:
composer global remove wp-coding-standards/wpcs
You may also want to delete the related folders in:
%APPDATA%\Composer\vendor\
6. How can I use different standards for different projects?
phpcs.xml
in each project directory. PHPCS will automatically use the closest configuration file in the directory tree when run inside that folder.Final Words
Setting up PHP_CodeSniffer with WordPress Coding Standards (WPCS) might feel like a lot of steps at first—but once it’s done, it becomes a powerful ally in maintaining clean, consistent, and professional-quality WordPress code.
By following this guide, you’ve:
Installed PHPCS system-wide
Integrated WordPress-specific standards
Configured your environment for global and project-level linting
Learned how to fix and review code issues automatically
This setup not only improves the quality of your codebase but also streamlines collaboration in team environments. Over time, you’ll notice fewer bugs, more maintainable code, and increased confidence when committing changes.
🔧 Keep your tools sharp and your code cleaner. Happy coding with WordPress! 💻✨
Would you like me to compile the entire article + FAQ + conclusion into a downloadable Markdown or PDF file?