Best Practices – WordPress Coding Standards

| Last Updated: | In: WordPress


Are you WordPress beginners or WordPress professionals? In this tutorial, I will explain Best Practices – WordPress Coding Standards. After this tutorial, you will able to know the WordPress coding standard.

I have worked on WordPress more than 5+ years to develop awesome websites, custom themes, and plugins and also contributed 10 plugins.

wordpress-beginner-guide

Why have coding standards?

Coding standard help you to avoid some common coding errors and improve the readability of your code and it is also easy to understand and modification. Just assume there are more than 10+ team member working on the same project and if all are following the WordPress coding standard, then it will ensure that all files of the project created by a single person.

Following are the coding standard which WordPress recommended and it is also the best practices. If you are planning to contribute to WordPress theme, plugin, and WordPress core, you need to follow the below coding standards.

  • CSS Coding Standards
  • HTML Coding Standards
  • PHP Coding Standards

CSS Coding Standards

Below is the coding CSS coding standard which you must be followed if you are trying to contribute to WordPress:

1) Always use the tabs instead of using spaces to indent each property of your CSS code.
2) Add two blank lines between sections and one blank line between blocks in a section.
3) Each selector should be its own line, ending with a comma or opening curly brace.
4) Properties should be followed by a colon and space.
5) All CSS properties and values will be in lowercase.

Correct Way to write CSS code

Incorrect Way to write CSS code

Below are the multiple CSS class you define in your stylesheet files. Follow the below coding standard:

Correct Way to write CSS code

Incorrect Way to write CSS code

HTML Coding Standards

All HTML tags must be closed properly. According to the W3C validation for HTML, all attributes must have the value and must be in single or double quotes. See the below example:

Correct Way

Incorrect Way

HTML Code Indentation

Also always use the tabs instead of using spaces to the indentation of your HTML code and PHP codes.

Correct Way

Incorrect Way

PHP Coding Standards

WordPress working continuouslly to improve the coding standard by helping WordPress users to maintain a coding style consistent. Use the tabs not the spaces to indentate your PHP codes below are the some examples of PHP code indentation:

Open and close curly braces must be used for all blocks even when they are not required shown here:

For the more detail about WordPress coding standard from here Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.

Tags: , , , , ,


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby.


You may also like:

Get Free Access of 450+ Scripts

Don't worry you'll not be spammed!

Featured eBook

WordPress Security Guide

Free Guide: Learn how to implement security guideline in your WordPress site...

DOWNLOAD

Free WordPress Setup Service

Free WordPress Setup

Want to Setup WordPress Blog Setup? I will help you in the setup of your WordPress blog.

Click Here

Pincode Finder

pincode-finder tool

Online Pincode Finder

Best tool to locate post Office address and pincodes of all india...

SEARCH NOW