WordPress PHP Coding Standards

Every coders can write the code which can leads to the output.

But some of us knows the standards. Even if you won’t follow the coding standards you will get the proper output.

We should need to habituated to follow standards to write the proper code. If some one needs to continue our pending work and we haven’t managed code in proper standards then the other one who is not aware with the functionality will not get the proper understanding of the existing code.

Here I have mentioned some basic standards which needs to follow for the WordPress PHP code.

  • Using Single and Double Quotes
  • Indentation
  • Proper Usage of Space
  • Naming Conventions

Let us go through each of these points.

Using Single and Double Quotes

As per the standards has been mentioned if you are not evaluating anything in the string, then you should use single quotes. Otherwise, You should always prefer double quote for the strings.


echo '<a href="www.url.com" title="Contact">Contact US</a>';
echo "<a href='$cta_link' title='$cta_title'>$cta_label</a>";


Another important thing that you need to use proper indentation. The reason behind that is, It always reflects the logical structure of your code. Always use tabs for indentation instead of space.

Tabs should be used at the beginning of the line for indentation, while spaces can be used mid-line for alignment.

Proper Usage of Space

Always put spaces after commas, and on both sides of the logical, comparison, string, and assignment operators.


x === 23
word && press
! word
array( 1, 2, 3 )
$cat . '-5'
$term .= 'X‘

Naming Conventions

Always use lowercase letters in a variable, action/filter, and function names (never camelCase). Separate words via underscores not with the dash. Don’t use variable names unnecessarily; let the code be clear.


function some_name( $some_variable ) { [...] }

Class names should use capitalized words separated by underscores. Any acronyms should be all upper case.


class Walker_Category extends Walker { [...] }

Files should be named descriptively using lowercase letters. Hyphens should separate words.



It’s a good practice to use coding standards.

Submit a Comment

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


Select Categories