Day 16: WordPress Coding Standards

Module: Coding Standards and Best Practices
Topics: WordPress Coding Standards (WPCS)

WordPress Coding Standards

WordPress coding standards are predefined techniques, if we introduce something on our own then it will be called a coding convention.

PHP Coding Standards
  • In WordPress, we use real tabs and not spaces
  • Use “elseif” and not else if.
  • Constants should be in all UPPER-CASE with underscore separating words.
define('UPPER_CASE', true);
PHP Coding Standards
  • No whitespace at the end of the line or on blank lines.
  • Use single-quotes for string literals.
  • Always include extra spaces around elements and arguments.
foo( options, object[ property ] );
HTML Coding Standards
  • All tags and attributes must be written in lowercase.
  • Always quote attributes
  • Self-closing tags should have exactly one space before the forward slash:
<br />
CSS Coding Standards
  • Attribute selectors should use double quotes around values.
  • Properties should be followed by a colon and a space.
  • Rule sets for media queries should be indented one level in:
@media all and (min-height: 1024px) {
  /* Your selectors */
}

WordPress Internationalization and Localization

What is Internationalization and Translation?

Internationalization is a way to add options to your application to handle different languages, Localization describes the subsequent process of translating an internationalized theme.

Components for i18n and l10n

gettext is a UNIX library that helps in creating and writing localizations and they are not system-specific.

pot file has 2 properties, msgid and msgstr.

Creating Translatable Strings

Leave a Reply

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