Open up fifty different WordPress themes and you’ll see fifty different ways to code a WordPress theme. While there’s no specific right or wrong way to code and structure your theme, there are several best practices I’d like to point out. Following these can decrease load time, allow you to code faster and allow the client to be able to understand and use the admin area better.

Use A Barebones Theme

A lot of the code you use for WordPress is pretty much the same from theme to theme. Instead of “reinventing the wheel” each time, simply start each project with a barebones theme. You can roll your own, or download one from a cool developer…

Reset Your Loops

The difference between a n00b developer and one that really knows the ins and outs of WordPress is that one can really use multiple loops to accomplish anything. When I first started in WordPress, it never occurred to me that it was possible to use more than one loop on a page – until it did. Unfortunately, just adding more loops never works. Instead, you’ll need to add wp_reset_query() to the end of your loop. You’ll never have a loop issue again.

Reduce Dynamic Calls

Unfortunately, this really only works if the theme you’re working on is for yourself or a domain you know about. WordPress has a fantastic amount of ready-made functions, but the over use of the bloginfo function can really slow down your site. instead of using bloginfo(‘template_url’) and bloginfo(‘siteurl’), try replacing those with the actual path. It can significantly speed up your site and reduce the amount of DB calls.

Use Custom Fields

Custom fields are fantastic for allowing clients to add or edit anything, from regular content to custom banners and backgrounds. I prefer to use custom fields instead of option panels, it reduces coding time, allows the client to keep all of the pages content in one section and is less confusing about where to go.

Forget Page Templates

Before WordPress 3 came out, it was pretty common to use page templates for every page layout. I still see some themes like this, but I think it’s a lot cleaner in the backend to put all of your page layout code inside of page.php…unless it’s something drastically different from the rest of the pages (or is a commercial theme where the user needs to be able to assign it to any page). Have the page layout switch dynamically reduces support clients when the client forgets he needs to assign a page template. Instead, the page layout is assigned by ID, or its parent-child relationship.

Javascript at the Bottom

A good coding tip in general, it’s especially important in WordPress, as WordPress can be a resource hog if not coded properly. Make sure you keep your JS links (because your actual JS is in its own folder) in the footer right before the closing body tag. This makes sure that if something breaks, the rest of the page will load and not get hung up.

Reduce Amount of Plugins

Depending on the type of plugins you use, it’s possible to have 20+ and not slow down the site, but it’s difficult for the client to know the difference between good and bad plugins. If it can be coded quickly, don’t use a plugin. Custom coding is always quicker in load times than using a plugin. Plus it reduces maintenance time and is one less thing you’ll need to keep updating, which brings me to….

Keep Everything Updated

WordPress is very secure…until you go several versions without upgrading. Always make sure your plugins and the actual WP site are always updated. It literally takes one click on a button to do.

Your Best Practices

What are some of the best practices you adhere to when working in WordPress?

Amber Weinberg

Amber is a freelance front-end developer specializing in semantic and accessible custom WordPress themes. She works with agencies and other freelancers to bring their designs to life using custom ACF flexible layout builds - making them more performant and less buggy while allowing the client easy customization without breaking the design system.