• Hello there, folks.

    The other day I was making a new theme by modifying a copy of the default theme. I changed a few things in header.php, footer.php, and style.css, but left the other files alone. Then I deleted all of the unchanged files, so that my custom theme folder contained only the three modified files. I reloaded my site and was rewarded with a blank screen.

    I had expected WordPress to fall back to the default theme when a needed file isn’t found in a custom theme, a sort of graceful degradation. But when I started searching around for reasons why this wasn’t happening, I found that WordPress uses all of the template files in a theme or none of them, there is no middle ground. In my opinion, this is not only counter-intuitive, but invites custom themes to become dated more rapidly than necessary. It seems logical that a custom theme should contain only those files that have been modified, so that future changes to the default theme may be automatically inherited by a custom theme.

    Ryan’s post at https://www.ads-software.com/support/topic/23641?replies=19#post-133810 indicates that a similar functionality was available, but has since been removed. The stated reasons for this were (i) added confusion and (ii) increased load times as WordPress goes “looking in multiple locations in order to put a theme together.” In response to (ii), WordPress could determine the path to each file when the theme is activated and store the paths for later reference; it wouldn’t necessarily need to construct the theme anew with each page load.

    Taking this a step further, using a method similar to the current style.css template header “Template: default” method of assigning inheritance, a custom theme could assign a second theme to initially fall back on, which second theme would then fall back on another theme, if desired, or the default, and so on, until all of the files are located.

    In the same thread, Ryan suggests that the theme behavior I’m describing can be accomplished with a plugin. This is beyond my current ability, but if anyone out there has a hack or plugin to make WordPress fall back to a file in the default template when the expected file isn’t found in a custom theme folder, please let me know.

    Thanks a bundle,
    -Oliver

Viewing 6 replies - 1 through 6 (of 6 total)
  • I don’t really understand what the big deal is. A theme only needs an index.php file and style.css. Anything else is gravy.

    If WP reverted to the default theme for templates that aren’t in a theme file, then you’d have to have some system to over ride that function. If I choose not to have a single.php file in my theme, I certainly wouldn’t want WP to assume I wanted to use the default one.

    Thread Starter ardamis

    (@ardamis)

    So maybe WP doesn’t revert until you instruct it to do so, by telling it which folder to revert to, using something like the “Template: default” theme header.

    I’m trying to future-proof a theme here. Let’s say the only template file in my custom theme folder is footer.php. My theme is set to fall back on the default theme, which is currently v1.6. Fast foward to a year from now. WP uses a substantially different default theme, let’s call it v3.02, with all sorts of wonderful new functionality built in. Without any effort on my part beyond upgrading WP, my theme picks up this new functionality from all of the default theme files that don’t exist in my custom theme.

    You are assuming everyone would be building their theme off of default, as you must be. Footer.php generally has some closing divs for any containers that are opened in header.php. What if a future default theme has more opening divs in header? Your footer.php then wouldn’t have the proper closing divs. Thus breaking the site.
    True, you could edit that one file, but that is a crap shoot to compare a theme today to one a year from now. Not to mention, guessing what kind of template tags will be in/or how they function, a year from now.

    How difficult is it to simply copy the default files to your new theme? How much server space can that really take? And if space is an issue, just delete the existing default theme from the server, it’s not like they can’t be downloaded again, quite easily.

    Thread Starter ardamis

    (@ardamis)

    I’ve acquiesced on the automatic fall back suggestion, admitting that an opt-in method is preferable.

    And I admit that there are some drawbacks to inheriting partial themes, including the possibility that the inherited files won’t sync up with the custom files.

    But instead of telling me how to do something, you’re insisting that I don’t need, or really don’t want, to do it in the first place.

    For the sake of argument, which isn’t why I’m here, incidently, let’s suppose that I have priviledged information about how the themes in question have been constructed, and all the practical problems concerning divs being closed have been worked out.

    Let’s further suppose that I’m not talking about my single personal site which I can treat like a work of art, but that I’m coming from a position where I need to manage dozens or even hundreds of domains, hypothetically speaking, let’s say thousands of sites. These thousands of sites each have unique themes built (read: cobbled together) by dozens of different people of disparate ability over a long period of time. Many of the themes are, as you suggest, copies of the default template with changes to a few files. Now imagine you are responsible for making particular changes to these themes. How would you efficiently make changes to these sites? How would you pick out which files have been intentionally changed and are therefore critical and which files are just copies of a 16-month old and aging version of the default which could be harmlessly replaced? The effort involved in manually downloading, evaluating, changing, and re-uploading each template file in this morass of domains makes my brain swim. I’m trying to find a logical way to facilitate updating a theme in a pretty difficult working environment, hypothetically speaking, of course.

    But maybe I’m barking up the wrong tree, your best thoughts?

    First, let me say, I’m not a sys admin, so my replies aren’t intended to seem technically perfect, nor am I here to argue. I wasn’t intending to “tell you how to do something”, I was speaking my opinion on the idea of including in the core of WP the fall back on the default theme’s files. Regarding the “priviledged” information regarding how a theme is constructed, I’m not sure what that means. Most of the code is in php, so viewing source won’t give away any code secrets, and well, I’m sure there are ways to hide a CSS file from prying eyes if that’s your wish, but that was never discussed in the original posts.

    That said, with my FTP client and server, I can see modified dates on the files.

    And if I’m managing many sites/blogs/etc, I’m doing periodic backups, so I know when the last time I backed up, upgraded etc. So I can easily see which files have been modified since install, etc.

    Not to mention, from a unix stand point, I know enough about it to know you can compare files and do diffs, etc. I’m guessing anyone managing that many sites knows more about sys admin than I, and is more proficient in *nix than I.

    Truth of the matter is, if I’m going to single handedly try to manage that many sites, upgrading themes, files, etc, I’m either charging for it, or I’m putting limits on what can be changed. I’d institute a style switcher system ala sandbox or K2, and offer widgets, but not changes to core templates in the theme.
    Not to say you couldn’t write/hire someone to write a plugin that pulled files from a single source if the template wasn’t in the theme folder. I just argue it’s not something I’d like to see in the core.

    Thread Starter ardamis

    (@ardamis)

    The priviledged information thing was just me being wordy. I simply meant that I would monitor the theme files to make sure they did sync up, in an attempt to put to rest some of your objections and to progress the conversation. Because, in the end, the “why” is irrelevant. I could probably think up a few more reasons why someone would want this functionality, none of which may convince you or anyone else of its worth, but that wouldn’t get me any closer to a plugin.

    You are quite right that, if the changes to the theme behavior described in this thread ever made it into the core, WordPress would become more complicated, most likely to its detriment.

    So, to return circuitously to the last paragraph in my first post, is there someone out there who would be willing to help by either developing such a plugin or putting me on the correct path by pointing out the hooks and things I would need?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Missing Template Files Makes WP Fall Back on Default?’ is closed to new replies.