
Tired of WordPress core nagging you about coding style inconsistencies in your plugins or themes? Fear not! This guide will walk you through setting up PHP CodeSniffer (PHPCS) with the WordPress Coding Standard (WPCS). Get ready to write clean, consistent, and future-proof WordPress code that adheres to best practices. Let's dive in!
Setting up Composer
The first thing you need to do is install Composer if you don't have it already. I'm not going to go into great detail about how to install composer since it's already documented on their website.
After that, navigate to the root fo your project and create a composer.json file (if you don't have it already) by typing composer init.
WordPress Coding Standard
After you have installed Composer and have a composer.json in your project root type the following commands:
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer require --dev wp-coding-standards/wpcs
Custom Configuration File
Create a phpcs.xml file in the project root. Here's an example configuration you can use as a template:
PHP Code Sniffer Configuration File for WordPress
Composer Scripts
In this example we have added two scripts: lint and lint:fix. The lint
command shows all linting errors and warnings present in the configured
files, while the lint:fix command tries to automatically fix errors which
it can fix.
InsightImportant: The
lint:fixcommand can't fix all commands thelintcommand can find. These changes need to be fixed manually. Also: don't forget to add the .phpcs.cache folder to your .gitignore file.
json{ "scripts": { "lint": "./vendor/bin/phpcs --standard=phpcs.xml", "lint:fix": "./vendor/bin/phpcbf --standard=phpcs.xml" } }
Additional Steps
Once you've completed the steps you're pretty much done. You can now use the scripts to check your code for inconsistencies and fix errors.
You could add the composer lint command to your pre-commit hooks or to your CI/CD workflows to ensure that no un-linted code slips through the cracks.
References
Enjoyed this article?
Join the newsletter to get my latest tutorials on Next.js, Sanity, and Web Development delivered straight to your inbox.
You Might Also Like

How to Add Settings Pages to WordPress Plugins: A Developer's Guide
4th Jan 2026
Hardcoding configuration values is bad practice. In this guide, we take our "Read Time" plugin to the next level by building a custom settings page. You will learn how to use the WordPress Settings API to securely save user input and make your plugin truly dynamic.

How to Create Your First WordPress Plugin: A Developer's Guide
28th Dec 2025
Still pasting code snippets into functions.php? It's time to level up. Learn how to decouple your logic from your theme and build your first WordPress plugin from scratch.

Optimizing and Cleaning Up Your WordPress Database: A DIY Guide
10th Sep 2024
As your WordPress project grows, you may begin to notice performance issues, often caused by a bloated database. While there are many plugins available to help clean up your database, sometimes it's good to know how to do it yourself. This guide will walk you through manually cleaning and optimizing your WordPress database.