From the Inbox: Updating Custom WordPress Themes Built On _S (Underscores)
Morten Rand-Hendriksen
AI & Ethics & Rights & Justice | Educator | TEDx Speaker | Neurodivergent System Thinker | Dad
In this first issue of #FromTheInbox, Mike asks a question I hear frequently:
“Once you develop themes using _S (Underscores), what are the best practices to updating them? With each WordPress update, won’t the theme eventually break? Are there beta releases for WordPress for testing purposes?”
There are multiple parts to this question, so I've chosen to break it down:
Q: What are the best practices for updating a theme built on the _S (Underscores) (or any other) starter theme?
A: When you build a custom theme based on a starter theme like _S, you are building something new. That means any updates that happen to the starter theme cannot automatically be applied to your custom theme. Any necessary updates are your responsibility, and have to be done manually.
When building a new custom WordPress theme, it is recommended to build it on top of an existing starter theme to ensure the core structure of the theme is sound. A popular starter theme I recommend is _S (pronounced “Underscores”) which has been referred to as a 1000 hour head start. I like this starter theme so much I've created an extensive course on Lynda.com that teaches you how to build a custom WordPress theme from scratch using _S.
This year, _S has spawned a new project called Components which adds modularization to the popular code base, and _S is just one of many popular starter themes you can work from. I mention this because the answer to Mike’s question applies to any custom theme, even those built from scratch without a starter theme.
The best practices for updating any custom theme are to follow WordPress Coding Standards and Accessibility Guidelines, and pay attention to upcoming changes and new features that will be introduced with new versions of WordPress. When making updates, provide a well documented Change Log to notify users and other developers of the changes introduced.
This leads to the next question:
Q: With each WordPress update, won’t the theme eventually break?
Short answer: If you follow WordPress Coding Standards, no, but you should still keep your theme up to date.
Long Answer: WordPress is built on a principle of backwards compatibility. When changes to existing functionality is introduced, it is done so that code written for older functionality continues to work. If the functionality being used in a theme or plugin is deprecated, WordPress will kick an error (visible in developer tools and if wp_debug is set to true), but the functionality will continue to work for the end-user.
This backwards compatibility is one of the reasons WordPress is so stable, and one of the reasons WordPress core development is so hard: You can’t simply shed the old code base or throw out old and deprecated functionality. Everything has to work, even if it’s old and no longer up to standard.
The number one reason why themes, plugins, and sites break with WordPress updates is poorly written code that does not follow WordPress coding standards. The most egregious error I see over and over is the introduction of custom functions with either a “wp_” prefix or no prefix. What can happen here is a function you created for your custom theme, something like “responsive_image_size();” is introduced as part of WordPress core in a later version. This would cause a PHP conflict that would take the entire site down.
The easy way to avoid this is to prefix all your functions and other custom elements with the name of the theme: “mytheme_responsive_image_size();”. That way there is zero risk that WordPress will ship a function with the same name in the future, and your theme won’t break with an update.
All that said, not updating your theme is a bad idea. First and foremost, coding standards change to make our sites more secure, and not updating your theme can mean making your users vulnerable to future security issues. Secondly, WordPress ships with new and exciting features all the time. To keep your theme current and allow its users to get the most out of WordPress, you need to keep your theme up to date. As an example, work is underway to introduce a new Theme Logo feature in version 4.5. To give users access to this feature, it has to be built into an updated version of your theme.
This leads to the final question:
Q: Are there beta releases for WordPress for testing purposes?
A: Yes. Alpha, Beta, and Release Candidates of future versions of WordPress are available and ready for testing purposes. To get a running log of the latest beta and RC releases you can follow the official WordPress Blog, and running the most recent bleeding edge version of WordPress is as simple as installing and configuring a plugin.
My recommendation is to set up a development environment on your computer and installing the WordPress Beta Tester Plugin. By configuring this plugin to update your site to “Bleeding Edge Nighlies”, you’ll always be running the most recent alpha, beta, or RC of WordPress.
Just a word of caution, early alpha versions may break things, and new features are sometimes added and then removed. When working with future features I recommend waiting until actual official betas are released before turning on Bleeding Edge Nightlies and doing any serious work. You should also pay close attention to the Core channel at make.wordpress.org to keep track of the discussions around these new features.
Hey, Morten: I want to ask a question!
I’m going to run this column on a semi-regular basis from now on. To do so, I need your questions. Have a question about WordPress, web development, web design, information philosophy, or some related topic? Leave it in the comments below and follow the #FromTheInbox hashtag to see if I pick your question as the basis of a future article. Though I can't answer all questions, I will try to cover those most frequently asked.
--
Morten Rand-Hendriksen is a Front End Web Development Teacher, Speaker, Workshop Trainer and Author specializing in web standards and WordPress. He's a full time Senior Staff Author at Lynda.com with more than 60 courses in the library. You can watch all his courses at Lynda.com/mor10, find him on just about any social media network @mor10, and read his personal musings on his blog at mor10.com.
Brand & Web Development.
5 年Hey Morten, I know this was written a while ago now... perhaps you're still monitoring? I'm trying to get away from packaged themes, and experimenting with underscores. This is one of my concerns... keeping "up-to-date". What would your workflow look like? Are you subscribed to Wordpress new code updates somehow (other than knowing there's a new version, I presumed you'd need all the nitty-gritty details in order to update your own theme)? When you see that there's a new feature, how do you go about incorporating that into your theme?? Maybe you've already written something with some examples of how this looks? Also, if you're building a site for a client, how would you go about it? Is it better to give them a theme they can update themselves? thanks Morten!