June 5, 2017 at 1:59 am #8000
I’m finding that in deveopment, I’m just leaving the site on my “secondary” theme and working from there is convenient. As I’m now moving the site over, I’m noticing that if I edit a page that had a template set from the “secondary” theme, I lose that template setting. Is there any workaround for this that I’m missing?June 13, 2017 at 2:12 pm #8049
Think of this as switching themes (because that’s what you’re doing). Whatever was assigned to the first theme will only work in the first theme. Whatever’s assigned in the second theme will only work in the second theme.
–DavidJune 13, 2017 at 2:30 pm #8069
Understood, but how how do people generally work around this? It’s not uncommon to need to change pages in both themes, no?
The two hacks I’m considering:
– Add dummy templates from one theme into the other. It appears that in the db, a post’s template is only saved as “template-name.php” – there is no path component to it, there is no reference to theme. So if in Theme A I have templates A and B, and in Theme B I have templates Y and Z, and Theme A is primary with Theme B being used on a few pages, I’d copy the templates Y and Z into theme A’s directory. These would not end up being used for display, but they would then show up in the page template dropdown when editing a page, which would allow editors to select the proper theme or just edit the page without breaking it or using “theme test drive”.
– Edit as normal, then in db backend “fix” the template selection directly in the postmeta table (_wp_page_template) after each edit.June 13, 2017 at 2:53 pm #8070
To be honest, my recommendation is to use a theme that provides multiple looks. I believe that something like Multiple Themes should be used only as a last resort. It’s definitely a hack and if you’re looking for a more reliable way to change looks on the fly, you should probably do it with a nice, commercially supported theme. If you dig through this site, you’ll notice that different pages look very different. I’m not using Multiple Themes. I just bought a copy of Divi and let it do all the hard work.
–DavidJune 23, 2017 at 2:01 am #8214
Absolutely, I get it!
That said, in my case we need to use an existing theme (in-house, FWIW), so no Divi. I’m also not a real fan of most of those monster themes that require constant updating and re-upping of support contracts to keep a site functional. YMMV, IMHO, etc.
For anyone landing here via a search, this is the quick fix to be able to have the multiple themes plugin active AND have all your page templates available in the page editor page template dropdown.
Given we have THEME-A and THEME-B, let’s assume THEME-A is our main/active theme and THEME-B is activated on a subdirectory via the Multiple Themes plugin, and we have a few page templates in each theme’s directory as below…
“Home Template” – home.php
“Contact Template” – contact.php
“Slideshow Template” – slideshow.php
“Gallery Template” – gallery.php
“Portfolio Template” – portfolio.php
So in the configuration outlined above, if you’re editing a page under THEME-B and that page is set to us the “Gallery Template”, you’ll find it doesn’t appear in the dropdown list of page templates. Worse, if you just edit something and save it, you’ll lose the page template setting and you’ll end up with the page rendering using the first fallback template for that theme.
Quick fix? Copy “gallery.php” and “porfolio.php” to THEME-A’s theme directory. I’d also suggest removing the contents of the file other than the top comment section that defines the template’s name.
Problems? Well, maybe you have a “contact.php” in both themes. In that case you’ll have to rename one of them AND re-save all pages using that theme. Also, is this hackish? YES!
How does it work? Why does it work?
Wordpress saves the name of the template in the post_meta table, and it saves the template not based on the pretty display name, but on the name of the actual template file (or “default” if no custom page template is used). It DOES NOT store any information on what the active theme is nor in what directory the page template is stored. So as long as we can trick WP into saving the right filename, we’re fine, and we trick it by making the file available in all themes we’re using. 🙂 See attached for how this looks in the db…
June 24, 2017 at 8:56 pm #8227
Wow. Very cool. Just remember: backup first.
You must be logged in to reply to this topic.