Not following coding standards creates:
- Inconsistent code - Different styles everywhere
- Hard to read - Mixed indentation, spacing
- Team friction - Everyone codes differently
- Review difficulties - Can't focus on logic
// Mixed indentation, no spaces
function processData($data){
if($data){
foreach($data as $item){
echo $item;
}
}
}
// CamelCase (wrong for WordPress)
function getUserPosts($userId) {
$postData = [];
}// Tabs, proper spacing
function process_data( array $data ): void {
if ( $data ) {
foreach ( $data as $item ) {
echo esc_html( $item );
}
}
}
// snake_case (WordPress standard)
function get_user_posts( int $user_id ): array {
$post_data = [];
}- Use TABS for indentation
- Use SPACES for alignment
snake_casefor functions and variablesPascalCasefor classesSCREAMING_SNAKE_CASEfor constants
- Space after
if,for,foreach,while - Space around operators:
$a + $b - Space after commas:
function( $a, $b ) - No space inside parentheses:
if ( $condition )
- Opening brace on same line
- Closing brace on new line
- Always use braces, even for single statements
// Good
if ( $condition ) {
do_something();
}
// Bad
if ($condition) do_something();- Always use full tags:
<?php ?> - Never use short tags:
<? ?>or<?= ?>
// Bad
$a = 1; $b = 2; $c = 3;
// Good
$a = 1;
$b = 2;
$c = 3;# Install
composer require --dev squizlabs/php_codesniffer
# Install WordPress standards
composer require --dev wp-coding-standards/wpcs
# Check files
phpcs --standard=WordPress file.php
# Auto-fix
phpcbf --standard=WordPress file.php- PHPStorm: Settings → PHP → Quality Tools → PHP_CodeSniffer
- VS Code: Install "phpcs" extension
- Sublime: Install "Phpcs" package
✅ Use tabs for indentation
✅ Use snake_case for functions/variables
✅ Space after keywords
✅ Always use full PHP tags
✅ Use WordPress functions
✅ Follow WPCS for consistency
❌ Don't mix indentation styles
❌ Don't use camelCase
❌ Don't skip braces
❌ Don't use short tags
Consistent code is easier to read, review, and maintain.
Follow WordPress Coding Standards for:
- Team consistency
- Easier code reviews
- Better collaboration
- Professional quality
Install phpcs and run it on every commit!