Best Practices






WordPress Coding Standards


If in doubt space it out

No one line conditionals

One line Conditional Example

BAD BAD BAD

Fixed



YODA Conditions




Don't be Smart



Readability is more important than clever code

Future you is not as smart as coffee fuelled current you




Other Best Practices

Single Responsibility


A function should do 1 thing


So what if we wanted to let people that can see holes download something as well?

Always GET and show


Look at WordPress Core
  • get_the_title()
  • the_title()

Shortcodes need data returned

Write a PHP Docblock First


Yup before you write code write down what it's going to do


My first stop in understanding a new project is to write docs for every function

Inline Explanations




If you need more than a docblock then you're likely being clever

No Closing ?>



Best Practices

By curtismchale

Best Practices

Some best practices for coding with WordPress, and coding in general.

  • 1,606