5 Cardinal Sins of WordPress Theme Development

5 Cardinal Sins of WordPress Theme Development

We talk alot on this site about tips and tricks for getting what you want out of WordPress… but today we’re going to take a step back from the technical stuff to look at some practices, bad habits, and coding faux pas that would be better left in our past. So, forgive the heavy-handed post title (haha!), we’re about talk bring up 5 surprisingly common practices that are blemishes on the platform.

Two of the nicest things about working on WordPress Themes is that fact that we get to target in an incredibly flexible environment (that is, the web) and we have solid documentation to help guide us through the process (that is, the WordPress Codex).

After all, if the theme works, does clean, maintainable code matter?

But there’s a danger that exists in theme development, too: we can completely forgo best practices for working with the web and completely ignore the documentation. Specifically, there’s nothing that forces us to write clean, maintainable code. After all, if the theme works, does clean, maintainable code matter? Furthermore, why go through the effort of following WordPress best practices if the theme appears to work fine?

Weak arguments, right? I don’t know – the more I’ve worked in the WordPress space, the more I’ve been surprised which how much bad code actually exists. As such, I thought it would be fun to outline five cardinal sins of WordPress Theme Development.


Ignoring The WordPress Codex

As with most programming languages, frameworks, or libraries, WordPress includes a massive amount of documentation. The WordPress Codex is arguably the best resource that developers have for working with WordPress. After all, it provides documentation for the majority of the application.

But the WordPress Codex often goes above and beyond standard documentation – in addition to supplying function names and parameters, the Codex provides rich examples for how to use many of the API functions. After reading any given article, you’d be hard pressed not to find a clear example of how to the function in question.

In addition to the API, the Codex also features a variety of other articles related to development:

Whenever I’m working on a theme or a plugin and I hit a point where I think I need to write a custom function to achieve something, I’ll search the Codex first. The majority of the time, a function is already available that helps with what I need.

Every serious WordPress Developer should regularly use the Codex when working on any WordPress-related development project. Ignoring it can often lead to creative, but untested and unstable solutions that can cause more harm down the line than good.


Not Localizing Your Theme

A few years ago, if you were to ask me my thoughts on localizing a WordPress Theme, I would’ve said that it would depend on the marketing that you’re targeting. That is, if you think the audience is going to use a language other than your own, definitely do it; otherwise, there’s nothing wrong with leaving the theme translated in your own language.

Fast forward a few years and WordPress’ is powering millions of sites on the Internet. Sites all over the world are using the application to drive their site’s content. On top of that, it’s becoming increasingly common for developers to supplement their income or even make a living off of working with WordPress.

Because WordPress has been so widely adopted and because the Internet has made the world so flat, the market for any given theme is not limited to a single language. On top of that, WordPress makes it so incredibly easy to localize your theme and it requires so little extra effort, that I now argue that localizing your theme is no longer optional.

For the most part, you need to understand three things:

Other than that, there’s very little extra overhead that comes with localizing a theme; however, I do recommend that you take a look at the Translating WordPress article in the Codex. It outlines the three things above and goes more in-depth on each.


Theme File Disorganization

Developers talk a lot about code organization and maintainability. Personally, I think that it’s much easier to give lip service to those principles than actually follow through with them, but they are important.

The thing is, they look different for each project type. Some applications are written in a single language and run on a desktop, some applications use two languages and run on a mobile device, other projects – such as WordPress Themes – can use anywhere from three (HTML, CSS, and PHP) to four (through JavaScript) languages. Additionally, certain components of the theme run on the client side, some run on the server side, some community directly with WordPress, and others communicate directly with the database.

To say that there’s potential to sacrifice maintainability is an understatement.

But it doesn’t have to be problematic as there are certain standards that WordPress suggests for organizing your theme files. Specifically, the Codex details how to organize your PHP template files, your stylesheets, JavaScript sources, and images.

  • Template File Checklist provides a listing of the files that compose a basic a theme and details what each should include.
  • Template Hierarchy provides an explanation for how all of the theme files fit together and how WordPress renders each during its page lifecycle.
  • Stepping Into Templates also provides a detailed breakdown of templates and the WordPress page structure for each.
  • Theme Development is a massive article that encompasses everything surrounding theme development.

Sure, it takes a little extra effort organize your files rather than just doing enough to “get it working,” but the dividends payout over time as you begin working on the next version of your theme or as multiple developers begin to work on the same codebase.


Disregarding Coding Standards

Of course, file organization is only part of the development process that affects organization and maintainability. Next, we have to focus on how we actually write the code that resides in our files.

After all, not only should we want to provide well-organized files, but easy-to-follow, standard-compliant code as well. Again, the WordPress Codex provides standard set for the major languages that contribute to a theme’s codebase:

A lot to process, huh? The thing is, spending time familiarizing yourself with all of the above pays dividends over time. Applying these standards at the beginning of development is exponentially cheaper than having to refactor an existing theme or plugin.

Additionally, it results in contributing better code back to the community.


Not Testing Your Work

After a theme has been developed and is ready for release, you should do – at the very least – a single of testing. That is, you should verify that the various styles of post data are formatted correctly, that your theme isn’t using any deprecated functions, or that it’s using any functions incorrectly.

Luckily, the Codex provides a number of suggestions and tools to help make this process much easier.

  • Debug mode helps to iron out any PHP warnings and/or errors
  • The Theme Unit Test is a data file including pre-formatted post data for you to run against your local development environment
  • Theme Check is a plugin that will examine that codebase of your theme and provide notes on what needs to be addressed as well as recommendations for improving the codebase.

Of course, there’s also additional testing you can do such as cross-browser testing, HTML/CSS standards compliance, and so on. The Codex outlines even more testing suggestions in the Theme Testing Process article.


What Are Your Own Pet Peeves?

They say that you often learn from your mistakes and I’ll be the first to admit that during my time with WordPress, I’ve broken every one of these. But, like the rest of the development community, you learn and you begin building better projects with experience.

This is the first of this type of “WordPress culture” articles that we’ll be posting on the site… so share your own experiences below – or better yet, write about them at length and we’ll publish it if it’s great!

That said, this is certainly not the definitive list and I’m sure there’s more to add (we haven’t even touched hacking the core, harassing the database, or hard coding elements that should have options). Drop your own pet peeves in the comments!

What are some of the most annoying, harmful, or unsustainable practices that you’ve come across?

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.youtube.com/user/izvarzone Some Guy

    I read some codex and I’m not agree with some stuff like disabled=”disabled” and required=”required” in html attributes, because that looks stupid for me. I just write disabled and required.

    Agree with other stuff.

    • Brandon Jones

      Good point… but the fact that you’re reading the codex to begin with is the important part. Devs reading it and disagreeing or coming up with a better solution is often how the entire platform gets improved ;)

    • Dave

      I’ve often seen required=”true” and disabled=”true”. This coding is just to conform with the standard that all attributes must have a value.

  • http://www.nomad-one.com nomadone

    Nice one, totally agree when there’s way too much non-wordpress code unnecessarily integrated into themes it makes it a real pain to repurpose them for client projects unless you’re able to read the mind of the developer.

    Personally I’m still quite sketchy on the localisation thing, would be good to have some more detail on the process. I’m no fan of the Codex as I’m more of a front end developer and find most of the codex assumes too much about skill levels in terms of implementing the various code suggestions.

    • http://thomasgbennett.com Thomas Bennett

      I would agree with localization. I’m simply not going to waste the time to the college’s website I’m working on that is located in the mid-south into other languages. In my opinion, WordPress itself has some pretty nasty code in it, so its kind of hard to say that you should organize things this way or that…

      But @nomadone – you should get into the Codex. It really is the most helpful thing out there. Even if you don’t really get it, the examples should clear it up. I’m on the frontend more too but knowing the WP functions are pretty critical to being efficient.

    • http://contempographicdesign.com Chris Robinson

      It might look a little daunting at first, but its actually pretty easy to localize your files:

      http://blog-en.icanlocalize.com/installing-wordpress-for-multiple-language-blogs/how-to-localize-wordpress-themes-and-plugins-with-gettext/

    • http://tom.mcfarl.in Tom McFarlin
      Author

      You’re right – the Codex is geared more towards server side programmers (at least they’re honest, right? :)); however, I’d agree that localization is usually pretty easy in WordPress.

      The main gotcha that I see is the neglect to call load_theme_textdomain. All strings can be localized but if this isn’t set, then no translation tool will pick them up..!

  • http://www.szek.net andi szekeres

    Good article!
    i`ve had some bad experiences with commercial WP Themes. the code was messy, wrong, patched, etc.

    the points you list in the article should be followed by any theme developer who respects his/her work.

    regards,
    andi

    • http://tom.mcfarl.in Tom McFarlin
      Author

      Thanks Andi!

  • http://www.customicondesign.com/ custom icon design

    very useful for me. I have read it carefully and I absolutely agree with the author’s viewpoint.

    • Thomas

      spam much?

  • http://www.webjobcentral.com John

    I have see a lot of themes that dont work browser to browser. I think a lot of developers look at it in one browser on one platform and call it finished. This is a pet peeve of mine, especially when I buy a theme, and it doesn’t work in IE7, and that is what the client is using. To me its just lazy, and shows the developer doesn’t know how to code correctly.

    • http://www.jaytillery.com Jay Tillery

      “To me its just lazy, and shows the developer doesn’t know how to code correctly.” Lazy, maybe. Doesn’t know how to code correctly? Let’s just say the developers disregarded cross browser testing of their theme. Something had to attract you to purchasing the theme. Right?

    • http://unrelatedmedia.ca Neil Davidson

      There are a lot of web developers who have been making a stand this past year and a half. A stand against Microsoft browsers. It’s actually hard to find a web developer who regularily codes specifically to keep cross-browser compatability.

      Its a sad truth, but not many want to give up on CSS 3 and many other things like HTML 5 just to be accessible in IE 6-8.

      I agree it should still be done, but were there a march agaisnt Microsoft and their incompatable browsers making life hell for developers…I’ll be at the front of that march!

      • http://tom.mcfarl.in Tom McFarlin
        Author

        I’ll even take this a step further and say that it’s not just developers who are beginning to take a stand.

        I’m self-employed and more and more projects that I’ve worked on in the latter half of this year have had clients wanting only to target IE9.

        I think that people are beginning – albeit it slowly – to understand the quickest way to kill the older browsers is to stop building things that work in them.

    • http://tom.mcfarl.in Tom McFarlin
      Author

      John, I totally get where you’re coming from – some projects absolutely should work cross-browser regardless of version, but I disagree that lack of support for older browsers demonstrates laziness or the inability to code correctly.

      Developers and clients alike make conscious decisions not to support those older browsers. I’d even venture to say that if you want 100% cross-browser compatibility, you have to resort to hacks which mean that you’re having to code incorrectly.

      In my opinion, all of this just shows that there’s no single right way to build stuff for the web.

  • http://www.jaytillery.com Jay Tillery

    The WordPress Codex is invaluable. Bookmark it, read it, play with it.

  • http://unrelatedmedia.ca Neil Davidson

    I agree with all points made. The odd exception is for localization and that is simply because there are two approaches made for theme development:

    Targeted
    Generic

    A targeted theme development would be for 40% of a typical developers work. That is to say building a theme for a local company or business that has no intention of reaching an international market or one that has a limited scope.

    Generic theme development is where localization is very important. It is a theme for any use or purpose, and anywhere in the world. Most purchased themes include this feature, and rightly so.

    @andi szekeres

    What you say is far too true. It’s called a bloated market. Not meaning to burn envato but they have the highest quality designs in their themeforest with the lowest quality coding I’ve ever seen in my 12 years in the industry. I’d give a loose ratio of 1:10 being effectively, and cleanly coded.

    In truth it comes down to quantity more then quality for marketable themes. The reason is simply due to themes quickly becoming dated as WordPress updates itself, or the company selling the theme changes their approach to meet demand.

    A great example is Envato’s own themeforest. At one point they stood up and said “no more crap, we only want high quality for our customers” and basically removed 90% of the themes and templates they had available. The first dozen entries were of the highest quality design and code. I think the Quality control personnel took a celebratory extended holiday since as the quality has declined substantially since then, yet again.

    Then again envato has to meet marketing demands and to do so they need to give up somewhere else.

    If you want good standards kept the best you can do is build it yourself, or purchase a theme from themeforest or other location and strip the code and rebuild it cleanly using the design.

    • Jon Hungerford

      I agree in part. I bought one theme of Envato which is excellently designed, one of the best I’ve seen visually. A developer of mine then had to spend several hours fixing the code to get it working with most plugins, it was an absolute mess.

      But I reiterate, the actual design was flawless. I sometimes buy Envato themes and give them to developers to say “Look. Here’s how good a WordPress theme can look. Make one.” Does give them inspiration…

  • http://www.logicdesign.co.uk/ Website Design Suffolk

    For me there are two cardinal sins with wordpress are firstly not using custom post types to their full potential – when you have content other than news dont just put them amongst the other posts.

    The other is the twenty ten or recently twenty eleven, most theme will all create for clients will be basic they just have pages and posts a custom menu and so on. The default themes provided are complex the do so much stuff and most of it is unhelpfull, spening most of your time removing bits so as not to confuse a client. Cardinal sin 2. – dont duplicate these themes, start from new.

    • http://tom.mcfarl.in Tom McFarlin
      Author

      I’m with you especially with respect to custom post types. I’ve got a software engineer background so custom post types along with custom meta data are great ways to model ‘objects’ in WordPress.

  • http://www.logicdesign.co.uk/ Chris Hollands

    Haha yes some good points, quite advanced tho! I think it’s worth saying for a novice that the WORST sin when it comes to WordPress is NEVER CHANGE THE CORE FILES! This will cause the wordpress site to break when it’s updated, obvious for even a novice but for a beginner it is worth being told!

    • Brandon Jones

      Good point Chris, although we’ve got some articles about that coming up (and this one is technically just “theme dev” sins, not general dev sins) :)

    • http://tom.mcfarl.in Tom McFarlin
      Author

      Chris – I’m with you 100%.

      There are a number of instances around the web – and even the WP Support Forums – that suggest changing WP application files for the sake of getting the functionality that you want (rather than, you know, using filters and actions :).

      Totally agree with you.

  • Pingback: How To Localize WordPress Themes and Plugins | Wptuts+

  • Pingback: My Stream » How To Localize WordPress Themes and Plugins

  • Pingback: wp-coder.net » WordPress News, Tutorials & Resources Roundup No.8

  • Pingback: Free Wordpress Themes Designs | Internet Marketing with Wordpress

  • Pingback: Tweet-Parade (no.46 Nov 2011) | gonzoblog.nl

  • http://www.bradley-davis.com/ Brad Davis

    The WordPress codex should be open as you code to make sure you you follow the highest standards in my honest opinion.

    • http://tom.mcfarl.in Tom McFarlin
      Author

      Yeah – it’s basically the developer’s manual to WordPress and over time you just learn the platform much more in-depth :).

  • Pingback: WordPress News, Tutorials & Resources Roundup No.8 | Customize WordPress Blog

  • http://www.fakeword.com/bands/ Random Name

    Boo Hiss! I’ve committed most of these sins. Need to up my game.

    Thanks for the list of suggestions, I’m going to have to actually learn PHP properly one of these days!

    PS – This site is incredible. Thumbs up for WP TUTS+!

    • http://tom.mcfarl.in Tom McFarlin
      Author

      At some point or another, we’ve all committed these sins. All is good, though – right? As long as we don’t keep doing them ;).

  • Pingback: WordPress Resource Roundup for the Week Ending November 19th - Charleston WordPress User Group

  • http://wayruro.com Renzo

    Greta article, I was thinking the Codex needs to be a bit more specific sometimes. As I learn about it is easier to understand it, but some months ago it was really confusing.

    Cheers!

    • http://tom.mcfarl.in Tom McFarlin
      Author

      There are definitely some weak areas of the Codex, but the fact that it’s growing and is even as developed as it is brings far above what so many other platforms offer.

      Take the good with the .. less good .. I suppose :).

  • Pingback: 7 Simple Rules: WordPress Plugin Development Best Practices | Wptuts+

  • http://www.tristarwebdesign.co.uk/ Paul Weston

    WordPress is very new to me and I am just starting to look into how to use it within my site design and builds. I have found this article very useful and will be using it as a constant reference. This article has given me a set of really good standards and practices to use from the start so I do not pick up bad habits and can produce successful WordPress sites and themes from the start.

    This has been a very detailed article with a lot of references to help me expand my knowledge and skills when it comes to WordPress.

    • http://tom.mcfarl.in Tom McFarlin
      Author

      Awesome! Exactly what I was aiming for with this article. I have a counter-part article coming soon, too…

  • Pingback: 7 Simple Rules: WordPress Plugin Development Best Practices | AIT Themes

  • Pingback: 7 Simple Rules: WordPress Plugin Development Best Practices | Graphfucker

  • Pingback: Best of Tuts+ in November | Flash Video Traning Source

  • Pingback: Best of Tuts+ in November 2011 | Omega Pixels

  • Pingback: Best of Tuts+ in November 2011 - Tutorial Finder

  • Pingback: Best of Tuts+ in November 2011 | CS5 Design

  • Pingback: Best of Tuts+ in November | Shadowtek | Hosting and Design Solutions

  • Pingback: Best of Tuts+ in November 2011 | Shadowtek | Hosting and Design Solutions

  • Pingback: Best of Tuts+ in November 2011 | Graphfucker

  • Pingback: Best of Tuts+ in November | clickshots

  • http://entropicstudio.net Entropic Studio

    I’ve been developing in WordPress for about 5 or 6 years now and I still feel like a newbie.. Thank you for providing these great insights!

    • http://www.yahoo.com/ Woods

      Your’s is the intllieegnt approach to this issue.

  • Pingback: Best of Tuts+ in November | Wptuts+

  • Pingback: My Stream » Best of Tuts+ in November

  • Pingback: Best of Tuts+ in November 2011 | Inspirations, dreams, humaniora

  • Pingback: A Free wordpress newsletter » WordPress News, Tutorials & Resources Roundup No.9

  • Pingback: Best of Tuts+ in November | linuxin.ro

  • Pingback: Best of Tuts+ in November | Freelancing Help

  • Pingback: Best of Tuts+ in November – blog

  • Pingback: Best of Tuts+ in November « Fast Ninja Blog by Freelanceful – Web Design | Coding | Freelancing

  • Pingback: Best of Tuts+ in November « CSS Tips

  • http://iva-is.me Iva

    Having read all of ther above, I would like to see a proper tutorial on how to make an options page using the API, for us who are designers and not developers.

    The existing ones are hard to understand.

    The alternate one, made by one of ThemeForest’s top contributors isn’t compilant with the Theme unit test.

    And so on….

    • http://tommcfarlin.com Tom McFarlin
      Author

      I’m working on this right now actually.

  • Pingback: Best of Tuts+ in November | cssWOW Showcase | Css Gallery | Css Awards | Design Inspiration Tutorials

  • Pingback: Best of Tuts+ in November 2011 | cssWOW Showcase | Css Gallery | Css Awards | Design Inspiration Tutorials

  • Pingback: Best of Tuts+ in November : Ahmad Assaf`s Blog

  • Pingback: Wanted: Bloggers | Graphfucker

  • Pingback: Wanted: Bloggers | Flash Video Traning Source

  • Pingback: Best of Tuts+ in November « Fernando Polania

  • Pingback: Best of Tuts+ in November 2011 « Fast Ninja Blog by Freelanceful – Web Design | Coding | Freelancing

  • Pingback: 5 "Saint-like" Qualities that All Wordpress Developers need | Wptuts+

  • Pingback: My Stream » 5 “Saintly” Practices that All WordPress Developers Should Strive For

  • Pingback: 5 “Saintly” Practices that All WordPress Developers Should Strive For | Graphfucker

  • Pingback: Best of Tuts+ in November - InterlaceLab

  • Pingback: Best of Tuts+ in November | Pro Sound Central

  • Pingback: Best of Tuts+ in November | Think And Design : Jordan webdesign and e-marketing

  • http://www.opensourcevarsity.com/ Meher

    Hi Tom,

    I am impress with the way this article has been written. The article is written from the point of view of a WordPress Theme developer.

    When I first started to learn how to create a WordPress Theme I had referred to E-book on how to create WordPress Themes. That time I was hesitate to use WordPress Codex as I found some of the articles on Codex confusing.

    Once I was successful in creating one WordPress Theme, I was confident I could create many more. But when the theme was tested I realized that there were some functionality missing.

    That is the time I start looking up in WordPress Codex and tried to understood the fundamentals of a WordPress Theme.. In a week or two I was able to rectify all the mistakes in the theme.

    All thanks to WordPress Codex… It is the best resource that developers have while working with a WordPress Theme. I would definitely recommend to all WordPress Theme Developer.

    When reading this article I also came across a plugin named – “Theme-Check” – that checks if the theme is following the latest theme standards. I am looking forward to trying and testing this plugin wonderful plugin.

    I am not sure if many WordPress developer would agree with me.

    In my opinion I feel that if WordPress Theme is given away free to download, why do some developer have to encrypted their signature in the Theme.

    If by any change the signature is removed the theme stops functioning. This forces the user to either change the theme or stick with the encrypted signature.

    Lastly I would love to thanks the writer for writing such useful tips and tricks for developing a WordPress Theme.

    Thanks and keep up the good work… :-)

    • http://tommcfarlin.com Tom McFarlin
      Author

      Meher – thanks so much for the comment! In addition to Theme Check, I also recommend Log Deprecated Notices.

  • Pingback: Best of Tuts+ in December 2011 | TrolWebDesign

  • Pingback: My Stream » Best of Tuts+ in December 2011

  • Pingback: Best of Tuts+ in December 2011 | linuxin.ro

  • Pingback: Best of Tuts+ in December 2011 | Freelancing Help

  • Pingback: Best of Tuts+ in December 2011 | Graphfucker

  • Pingback: Cardinal Sins of WordPress Development - Tom McFarlin

  • Pingback: עבודה טובה בוורדפרס | ליקוטי שיבולים

  • Pingback: Developing WordPress Plugins and Themes for the Public | Learning from Lorelle

  • http://www.facebook.com/mittul.chauhan Mittul Chauhan

    A useful intro indeed ..

  • Sara Williams

    I like to make an includes folder, and then my functions.php file points to stuff in there. I also use theme constants for certain things that get reused a lot, in replace of blog_info() for example. This article has become somewhat of a template for my constants: http://www.deluxeblogtips.com/2010/04/10-best-practices-for-wordpress-theme.html

    The other thing is to learn as much PHP as you can. Just because WordPress does all the heavy lifting for you doesn’t mean there won’t come a time when it’s useful. Even a designer should try to push themselves a bit with this. I can tighten up my themes with better organization and more DRY techniques because that’s what I did.

  • http://lucianmann.weebly.com/1/post/2013/05/wordpress-development-requires-no-technical-know-how-and-is-easy-to-use.html Paul Rollins

    WordPress Themes are information that work together to create the they of a WordPress website. Each Concept may be different, providing many options for online marketers to immediately change their website look.