What to do when theme and WordPress coding standards conflict?

This is a very subjective question — though a very good and interesting one, and I’ll try to provide my personal view on this.

In general, you should always try to adhere to the WordPress Coding Standards. The only exception to this is when you’re changing existing code. Basically, when you’re editing an existing “product” (e.g. a plugin or theme), you should use the coding standards the product follows. So, in your case you should adhere to the coding standards of the theme.

Even though this differentiation might seem quite black-and-white, it isn’t. There’s a lot of grey areas to consider. I’ll try to cover a few of those, but let me first try to give a set of basic rules:

  1. If you’re not changing a product but building a new one or extending an existing one, use the WordPress coding standards.
  2. If you’re changing code in WordPress core, use the WordPress coding standards (even though the additional code might not adhere to them).
  3. If you’re changing a product and the code is readable and consistent in formatting, use the original product’s coding standards.

In general, the most important thing of coding standards is to keep your code readable. So, when deciding whether you’re going to use the original coding standards or the WordPress coding standards, ask yourself the question: what makes the code in this product as a whole more readable, using the original or WordPress coding standards?

Coding standards for child themes

This isn’t actually a grey area, but it’s an interesting point to clarify: when extending a product (so not changing but really extending), you’re providing an additional product dependent on an existing product. This is a separate product, and you should adhere to the WordPress coding standards.

Ridiculous coding standards

If you’re changing a product and it has ridiculous coding standards (e.g. coding standards that severely damage code readability), you should opt for using the WordPress coding standards.

Inconsistent coding standards

If the original product doesn’t seem to be incosistent in adhering to a particular set of coding standards, you should use the WordPress coding standards for your own, new code.

Leave a Comment