WordPress-Feature-by-LucyBeerI work with new WordPress users and developers daily . Often times, these users are frustrated with WordPress, or what they think are WordPress problems. Generally speaking their frustrations are not with WordPress per se, it’s often with the theme they are using. Sometimes it’s a commercial theme, and sometimes it’s custom-created by a developer. In either case, they have hit a wall and usually this can be traced to poor development practices.

Code For The Future and for Others!
You must always assume your code will be touched by another developer in the future! You don’t want that developer (or your future self) cursing your name. If you have written shoddy code without following best practices, you’re making life for the next developer pretty hard. The following are specific tips to develop with consideration and elegance.

Screen Shot 2013-10-29 at 10.43.20 AM

Actual comments from the new (mt) WordPress blog in development

Comment your code well
This is something you hear time and time again, but it’s worth mentioning again. Documenting your code will help not only other developers understand what your thought process was when writing that spiffy function, but it will also help future-you when you need to tweak something in 8 months. It’s easy to forget what you were thinking at the time the code was written or why you did something a certain way. Your future self will thank you for your present self’s clear documentation.

Use coding standards
The core contributor handbook, found on Make.WordPress.org contains detailed info on how to structure and write your code so that it is “readable, meaningful, consistent, and beautiful.” It contains guidelines for writing CSS, HTML, JavaScript and PHP code.

Enqueue all the things
Gone are the days of hardcoding links to Google Fonts and other scripts into header.php. Enqueueing is the best way to include additional JavaScript files, stylesheets etc. This will help avoid collisions with plugins, avoid calling scripts multiple times or loading scripts on all pages unnecessarily. This will help future-proof your work by letting WordPress handle, for example, the version of jQuery that’s loaded, rather than hardcoding your own directly into the theme. There’s a lot of tutorials on this topic; one that I like, both for the article content and the extensive discussion in the comments section, is this one by Brian Krogsgard on WPCandy:

Become a better coder
Almost every developer, including the really, really good ones, will tell you they look at code they wrote last year, or maybe even 6 months ago to see how they could make it better based on what they have learned since. No one is born an advanced coder. Developers need to be open to change, feedback and learning.

Peer Review: Try to get your code reviewed by your peers if you can, or discuss with other developers their approach to solving coding problems.

Get Interpersonal: Meetups are a great place to meet other developers. Find a Meetup or a WordCamp in your area. If you don’t have access to a local meetup, there are great online communities such as the Advanced WordPress Group on Facebook.

Read the Experts: Follow the blogs of people like: Bill EricksonMark Jaquith, Justin Tadlock, Tom McFarlin, Pippin Williamson and Paul Underwood  to help cut your learning curve down and stay on top of best WordPress coding practices.

missing head and footer

Click to see the error messages

Use the Theme Check and the Theme Mentor plugins to improve your code. You can use both plugins simultaneously since they offer slightly different results. They will scan your theme code and show you a list of errors, problems or recommendations, based on what the WordPress Theme Reviewers team looks at in themes submitted for the repo.

Lucybeerprofilepic 2

About the Author: Lucy Beer is a web and WordPress consultant focused on making WordPress accessible to the beginner and a powerful development platform for the advanced user. Lucy runs Web Training Wheels and can be found speaking around the country or on Twitter.