How To Verify Coding Standards in WordPress-PHP

How To Verify Coding Standards in WordPress-PHP

How to verify coding standards in WordPress - PHP - blog image

When WordPress was developed, right from the start, Matt Mullenweg, the chief programmer and soon to be CEO of Automattic, the company behind WordPress, enforced a long list of rules regarding the code writing that every core contributor have to comply to. Those rules defines how the code should appear.

Coding standards have immense importance in developing for WordPress and everyone can implement those when developing for WordPress. It does not matter if you are writing customized plugin for your customer or child theme.

But first let us discuss about coding standards. Why should we use standards? Basically, the code should work, right? Why does anyone should care if there is only single space between the condition clauses or if the some documentation remark should start with a capital letter and end with a full stop?

Coding standards are very common in almost every framework and system. Code that is written by well-defined rules have huge advantages over code that it isn’t.

It is much easier to read. When code is written by several programmers, or by a single programmer over long stretch of time, it become very hard to read. It look like a book with no editor that several author wrote. Sometime private method will start with underscore prefix and sometimes it is not, sometime the variable are Camel Cased and sometime not. The spaces are not consistent and it is looks like a mess.

Also, using code standards can help mitigate errors. For example, matt, in his infinite wisdom, declared that ‘Yoda condition’ to be mandatory. It means that instead of:

If ( $var === true )

You should write:

If ( true === $var )

Why should anyone care about that? Unless of course if you have OCD…. The answer is simple. Using Yoda condition prevents accidental placement in the condition, thing that can drive you crazy.

Using code standards make your code look like solid, professional code. Code that pass code standards test, is a quality code.

Telling your clients or your boss that you are writing by WordPress code standards is something that can help you get that contract or get this raise in the salary. But there is huge gap between saying that you are working by the standards and actually working by those.

The code standards is basically a very long list, and it is hard to remember it all. So, how do we do it? Also, how do we allow the customer\manager to verify that the code is actually written by the standards?

This is why we have PHP Static code analysis tool that allow us to scan the code that we wrote and verify that the code follow every rule in the standards.

Using phpcs is quite easy on Linux or Windows. First, you must install phpcs via PEAR:

$ pear install PHP_CodeSniffer

Verify the installation by

$ phpcs -i

You should get something like that:

The installed coding standards are PHPCS, Squiz, PSR2, MySource, PEAR, Zend and PSR1

This allow you to scan the PHP code by various PHP known standards. We need to add WordPress standards to phpcs tool. We will create some directory (not temporal one) an clone to it the GitHub project of phpcs WordPress dictionary:

$ cd c:\wpcs

$ git clone -b master wpcs

After that, we will add the WordPress dictionary to phpcs:

$ phpcs –config-set installed_paths c:\path\to\wpcs

If we try php –I, we will see that WordPress dictionary is in there:

$ phpcs -i
The installed coding standards are PHPCS, Squiz, PSR2, MySource, PEAR, Zend, PSR1, WordPress, WordPress-VIP, WordPress-Core, WordPress-Docs and WordPress-Extra
Running phpcs is quite easy. Go to the directory of your code and type this:

$ phpcs –standard=WordPress ./**/*.php

That’s it! You will get a report on the issues immediately:

FILE: /var/www/html/github/wp-notice/tests/bootstrap.php
2 | ERROR | [ ] Missing file doc comment
4 | ERROR | [x] First condition of a multi-line IF statement must
| | directly follow the opening parenthesis
19 | ERROR | [ ] Missing function doc comment
19 | ERROR | [ ] Function name “_manually_load_plugin” is invalid;
| | only private methods should be prefixed with an
| | underscore
21 | ERROR | [x] File is being conditionally included; use “include”
| | instead
22 | ERROR | [x] File is being conditionally included; use “include”
| | instead

Getting zero errors reports is actually the goal here. Printing this report to clients and managers can show them that you write the code by the standards and your code have actually more quality than other code.

You can running phpcs automatically, and using other tool to fix several issues automatically. You can even combine the standards with your IDE to get notified immediately. But before all this, knowing the standards and know phpcs can put you and your code in a different level of quality.


If coding seems too confusing or time-consuming, you can easily create an amazing website in no time with the best website builders that require no coding skills at all.

Website Building Tools We Recommend for WordPress

ProviderUser RatingBest ForExpert & User Reviews 
4.6AI ToolsHostinger ReviewVisit Hostinger
4.5DesignSquarespace ReviewVisit Squarespace
.0PricingIONOS ReviewVisit IONOS

Do you need the best WordPress hosting? Check out for our recommendations by clicking here.

10 Best VPS Hosting on Reddit: Most Recommended Providers 2024

Reddit is a popular source for hosting recommendations, including VPS hosting. With multiple conversations on choosing a service and dozens o...
4 min read
Ela Gal-Kfir
Ela Gal-Kfir
Digital Marketing Specialist

HostAdvice Speaks to ScalaHosting: An Interview with Chris Rusev

HostAdvice had the opportunity to speak with Chris Rusev, the CEO and co-founder of , a web hosting company that offers shared, cloud VPS, and res...
8 min read
Eddie Segal
Eddie Segal
Digital Marketing Specialist

Email Deliverability: What Is It, Key Factors & Best Practices

What is Email Deliverability? Think of it like mailing a letter and making sure it lands right in the recipient's hands, not lost or thrown...
17 min read
Ela Gal-Kfir
Ela Gal-Kfir
Digital Marketing Specialist

Email Marketing vs. Social Media: Which is More Effective?

What is Email Marketing? Email marketing is a  that involves companies reaching out to potential and existing customers via email ...
10 min read
Ela Gal-Kfir
Ela Gal-Kfir
Digital Marketing Specialist provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top