Why Every WordPress Developer Should Use PHPCS and WordPress Coding Standards

If you are a WordPress developer and are writing code for use on multiple websites then you should be using coding standards.

As a developer you’ve probably heard fellow developers talk about PHPCS and WordPress Coding Standards. But are they really worth implementing in your workflow? The short answer is absolutely – and here’s why.

Think of coding standards as the grammar rules of programming. Just as proper grammar makes written content easier to understand, coding standards make your code more readable and maintainable. PHPCS (PHP CodeSniffer) acts as your personal code editor, catching mistakes and ensuring you follow these standards consistently.

When you’re deep in development mode, it’s easy to focus solely on making things work. However, writing clean, standardized code isn’t just about satisfying your inner perfectionist – it’s about creating sustainable, professional-grade plugins that stand the test of time. Whether you’re working solo or as part of a team, following WordPress Coding Standards through PHPCS brings numerous advantages to your development process.

First and foremost, it ensures your code maintains consistency with WordPress core. This isn’t just about following rules for the sake of it – it’s about creating plugins that integrate seamlessly with the WordPress ecosystem. When your code follows the same standards as WordPress core, it becomes more reliable, secure, and easier to maintain.

For team projects, PHPCS is particularly valuable. It acts as an automated code reviewer, catching potential issues before they make it into production. This means fewer bugs, better security, and more efficient code reviews. Plus, when everyone on the team follows the same standards, collaboration becomes much smoother.

But perhaps the most compelling reason to use PHPCS and WordPress Coding Standards is the long-term benefit to your development practice. As your plugins grow and evolve, having standardized, well-documented code makes updates and maintenance significantly easier. It also makes your code more accessible to other developers who might need to work with it in the future.

The best part? Modern development tools make it easier than ever to implement these standards. With PHPCS, you can automate the process of checking your code against WordPress standards, catching issues early in the development cycle. Many popular IDEs and text editors offer integration with PHPCS, making it a seamless part of your workflow.

Whether you’re a seasoned WordPress developer or just starting your journey, implementing PHPCS and WordPress Coding Standards is an investment in your code’s quality and longevity. It might take a little time to adjust at first, but the benefits to your development process and final product make it well worth the effort.

How to use PHP Coding standards on Mac

At MRK we all use MacOS as our primary development tool.

To make PHPCS work you need to have PHP running on your local machine.

I use a tool called “homebrew” to get that working.

By visiting there website you can get that working. Its not just for command line tools either, all sorts of things can be managed and installed with brew commands.

Once you have “homebrew” running you can paste a simple command to install PHPCS.

However that is only part of the solution. You still need to get WordPress coding standards on your local machine.

To set that up you need to pull down a couple of git repos.

First open terminal and change into the correct directory:

cd /opt/homebrew/bin

once you are in this folder you will need to pull in the following git repos.

First the WordPress coding standard – I use the develop branch.

git clone -b develop https://github.com/WordPress/WordPress-Coding-Standards.git wpcs

This will clone the WordPress coding standards into a WPCS folder.

Next, Clone in the PHPCUtils repo.

git clone https://github.com/PHPCSStandards/PHPCSUtils

Finally clone in the PHPCSStandards.

git clone https://github.com/PHPCSStandards/PHPCSExtra

This now means you have 3 new libraries.

Remember, you will have to keep these up to date so when ever you update PHP or other brew packages you will have to manually go into the locations and do a Git Pull to keep them up to date.

Now you have these libraries we need to tell PHPCS to look at them as additional standards.

This terminal command will get the result:

phpcs --config-set installed_paths /opt/homebrew/bin/wpcs,/opt/homebrew/bin/PHPCSUtils,/opt/homebrew/bin/PHPCSExtra

Next, run the “phpcs -i” command and you should see the new items available.

My output looks like the following:

This shows that I now have the various WordPress standards available inside “phpcs”.

Now that you have that running its now just a case on adding an extension to VS Code.

Here is the link to the tool I use.

The only setting you need to adjust to get started in the “phpcs executable path”.

Once these are enabled you will get prompts inside VS Code to fix code.

Yellow items are warnings and red are errors.

These show up in the Problems tab for each file in VS Code.

Showing these problems is a big advantage to finding code issues. It also keeps everything consistent.

If you want to use a beautifier to auto format code you can now do that too.

I use the PHP_CodeSniffer library to get this working.

Once activated you can use the format selection or document tools to automatically fix errors.

Its a huge time saver.

I hope you like these tips for WordPress developers. You can checkout other guides and tools in the suggest reading below.