Use of PHPCS and PHPCBF in WordPress

Once you have installed PHP_CodeSniffer (PHPCS) and PHP Code Beautifier and Fixer (PHPCBF), you can use them to check and fix coding standards for a specific file or directory. Here’s how you can use them:

PHPCS (Checking Coding Standards):

For a Single File:

phpcs /path/to/your/file.php

For a Directory:

phpcs /path/to/your/directory

Example with WordPress Coding Standards:

phpcs --standard=WordPress /path/to/your/file.php

PHPCBF (Fixing Coding Standards):

For a Single File:

phpcbf /path/to/your/file.php

For a Directory:

phpcbf /path/to/your/directory

Example with WordPress Coding Standards:

phpcbf --standard=WordPress /path/to/your/file.php


  • Make sure to replace /path/to/your/file.php or /path/to/your/directory with the actual path to your PHP file or directory.
  • The --standard flag allows you to specify which coding standard to use. In the example, it’s set to WordPress.

After running these commands, PHPCS will check your code against the specified coding standard, and PHPCBF will automatically fix some of the issues.

Remember to review the changes made by PHPCBF, as it may not catch all issues, and manual intervention may be needed for certain cases.

You can customize the rules and configurations by creating a phpcs.xml.dist file in your project directory. This file allows you to specify additional settings and rulesets for PHPCS.

Leave a comment

Your email address will not be published. Required fields are marked *