WordPress coding standards

WordPress has a set of coding standards that developers should follow when writing code for the platform. These standards are intended to make WordPress code more consistent, easy to read, and maintainable.

Here are some of the main coding standards that WordPress developers should follow:

  1. Use tabs for indentation: WordPress uses tabs for indentation, not spaces. This helps to ensure that code is properly formatted and easy to read.
  2. Use lowercase for all PHP files and functions: All PHP files and functions should be written in lowercase to help prevent naming conflicts.
  3. Use PHP closing tags: All PHP files should use closing tags (?>) to help prevent unintended whitespace from being added to the end of the file.
  4. Use double quotes for strings: When writing strings in PHP, use double quotes (") instead of single quotes ('). This allows you to use variables and escape sequences inside your strings more easily.
  5. Use camelCase for functions and variables: WordPress uses camelCase (e.g. myVariable) for functions and variables, rather than snake_case (e.g. my_variable).
  6. Use meaningful and descriptive names: When naming functions, variables, and other code elements, use meaningful and descriptive names that accurately reflect their purpose. This makes your code easier to understand and maintain.
  7. Follow WordPress coding conventions: In addition to the general coding standards outlined above, WordPress has specific conventions for various types of code, such as PHP, HTML, and CSS. It’s important to familiarize yourself with these conventions and follow them consistently to ensure that your code is compliant with WordPress standards.

Here are a few more things to consider when working with WordPress coding standards:

  • Use the WordPress code style plugin: WordPress has a code style plugin that can help you ensure that your code follows WordPress coding standards. The plugin integrates with popular code editors like Visual Studio Code and checks your code for style issues as you write it.
  • Use the WordPress VIP coding standards: If you are working on a project for WordPress.com VIP, you should follow the WordPress VIP coding standards. These standards are more strict than the general WordPress coding standards and are intended to ensure that code is of the highest quality and meets the security and performance requirements of the VIP platform.
  • Use the WordPress Coding Standards Handbook: The WordPress Coding Standards Handbook is a comprehensive guide to WordPress coding standards and best practices. It covers a wide range of topics, including PHP, HTML, CSS, and JavaScript, and includes examples and explanations to help you understand how to apply the standards in your own code.
  • Review and test your code: Before you submit your code for review or use it in a live environment, it’s important to carefully review and test it to ensure that it meets WordPress coding standards and functions as intended. This includes checking for syntax errors, testing for compatibility with different browsers and devices, and verifying that your code follows best practices and conventions.

I hope this helps! If you have any more questions or need further guidance, don’t hesitate to ask.