Why I Don't Follow WordPress Coding Styles?
I'll discuss why I don't use WordPress Coding Style when creating WordPress solutions and what I use instead.
If you work with WordPress you must have heard about the official rules that must be followed while contributing to the core. It's great that they exist because they help keep the code consistent, which is crucial in such project size, but I don't like some of them.
⚠️ Be aware that this topic primarily refers to the process of creating custom WordPress solutions and touches on the visual aspects of the code, which may vary from person to person. If you're looking for a general guide about WordPress Coding Standards to understand how they can help us protect our investment, let's check out this guide.
Are WordPress Coding Styles Bad?
For me, keeping the class-
prefix for class file names, when I use a more structured approach, seems to be unnecessary duplication. Putting spaces on both sides of parentheses looks ugly as well as a long array syntax instead of a short one. Yoda conditions make the code readability worse too! I can not ignore the worst part, using tabs instead of spaces.
- class Post {} // src/Posts/class-post.php
+ class Post {} // src/Posts/Post.php
- function my_function( $param1 = 'foo', $param2 = 'bar' ) {}
+ function my_function($param1 = 'foo', $param2 = 'bar') {}
- $my_array = array( 1, 2, 3 );
+ $my_array = [1, 2, 3];
- if ( true === $the_force ) {}
+ if ($the_force === $true) {}
Don’t get me wrong! We talk about tastes so I don’t mean that they are all wrong. I don't want to convince you that green is better than blue. Also, they have many great rules, like forbidden PHP short tags, one object structure per file, or requiring visibility declarations in classes, but for some of them, I just have a slightly different taste.
- <?= esc_html( $var ) ?>
+ <?php echo esc_html( $var ); ?>
- class Post {} // classes.php
- class Media {} // classes.php
+ class Post {} // src/Post.php
+ class Media {} // src/Media.php
class Foo {
- string $foo;
+ private string $foo;
- function bar() {}
+ public function bar() {}
}
I also share Josh Pollock's opinion in this area. It states that following the established best practices for PHP development makes more sense and doing so leads to better, more maintainable, and more interoperable code. I often try to search for solutions that help to prepare for more interesting development opportunities, especially if they don't affect negatively my, or my client's business and that's why it's just easier to follow wider used rules.
What Coding Styles I Use in WordPress?
The rules defined by the PHP FIG group - standards committee for PHP development - like PSR-1 or PSR-12, are much more widely used than the ones defined by WordPress. Laravel uses PSR, and Symfony is built on PSR too. Since I mostly try to write code that doesn't limit me just to one ecosystem when I can, I choose "The PHP way" rather than "The WordPress way" by default. It opens the door for other projects and stacks.
Also with the right approach, we can build reusable code decoupled from infrastructure, meaning that we could use some parts of the code even outside WordPress. If the code adheres to widely used standards, it’s better to fit them in other stacks. Of course, this argument can be easily undermined because there are tools like phpcbf
, but still good.
So to sum it up, while creating themes and plugins I use PSR-12 for coding with a few custom additions, and PSR-4 for autoloading. When committing to the core, there’s no other option than using official guidelines. That’s required by the project itself.
Which Coding Styles Should You Choose?
I have no power to answer this. Remember that in cases like this, we talk about tastes so choose the standard that fits your needs and use it. You have many options like PEAR, PSR1, PSR12, PSR2, Squiz, Zend, WordPress and many more.
You can even build your own coding standards which have been widely discussed in the previous material so check it out if you want to learn how to achieve this! Our team has been using PSR-12 for a long time and never had a problem with it.
What about you? Let me know in the comments which coding standards you use for developing WordPress solutions and why. WordPress? PSR? Or maybe the custom one?

Looking for a developer who
truly cares about your business?
My team and I provide expert consultations, top-notch coding, and comprehensive audits to elevate your success.
Feedback
How satisfied you are after reading this article?