-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for using regular WordPress theme templates in AMP, in paired or canonical modes #827
Comments
One of my goals for AMP is to make the template system more WordPressy. Actually, the ultimate goal is to make WordPress themes themselves to be AMP-compatible, that is, Canonical AMP (#668). This will require that we make sure that WordPress's own templating system can be made to output only that which is AMP compatible, or to output-buffer the output and sanitize the entire rendered HTML. More discovery needs to be done on the best way to implement the AMP canonical themes. Nevertheless, in the mean time for the exiting paired mode and the current AMP theming system, I do agree we should switch to If you can identify a backwards-compatible PR then I'd be happy to review. |
@westonruter Interesting. Thanks for the super-fast reply. Let me see what I can come up with. |
@westonruter How stable is the current |
@mikeschinkel use |
@westonruter Okay, so with the first PR passing all tests I'm ready to move on to the actual need that got me involved; getting the plugin to support AMP on all theme templates. One of the biggest issues I currently see with the current architecture is that it allows plugin and site developers to couple their code Of course we could support the old way on current installs and the new way on new installs with a switch in the admin to disable/enable legacy support. Would you be open to that? And if so, then we need to discuss what the newer approach would actually look like. |
@westonruter It seems that you have some other code in development, likely to provide support for
So it seems we need to split that in two and create an In addition I would think that an We could use BTW, we could store a setting Just some strawman proposals. If you like this let me know so I can move forward with a proof-of-concept. But if not let me know your thoughts instead, please. |
Looking at a potential
Wouldn't a more WordPress-ish approach be?
Or?
Or?
Or my preference:
It also runs all the AMP transform processing on instantiation, calling these non-trivial functions:
Wouldn't a better way to do that work be on-demand? Here is what I propose:
(We have used these conventions in projects for over 3 years now and they work extremely well.) Let me know your thoughts. |
Yes, page support just landed. See #825 As for next steps on making AMP a first class citizen in WordPress themes (canonical AMP themes): I think we should move away from
These are the first handful of items that I see needing to be done. I'm sure there are more, but I'm expecting work to start on this very soon. |
What is "paired mode?"
Sounds like a great plan. I am on board with this.
By this I assume you mean if the templates do not abide by the bare requirements then the theme is simply not supported and the results are undefined?
If we are going to buffer everything, why do we need to do 4. and 5.? Why not just convert the entire output? Of course we could do 5. for specific widgets if we find it easier to fix a problem that way but it seems like we should be able to handle most things by just converting buffered output? BTW, I assume any custom JavaScript would need to be removed?
Right now getting a workable AMP theme is a critical path for me on a client project so I would like to offer to work on this starting as soon as I get your go-ahead with a goal to have it done ASAP. What do you think? -Mike P.S. I would also like the option to still have a custom AMP theme that serves separate from the regular WordPress theme in which case the buffering could be avoided. Maybe?:
|
Paired mode is what we have in the plugin today. Separate templates for AMP mode from templates that the site uses normally.
By this I mean that a theme is using valid AMP markup in it templates, and it vouches for this by doing
I think mainly because it is a waste of CPU. If templates are already AMP-compatible, then we should only care about sanitizing data that we know isn't or may not be AMP compatible. We could potentially run the entire HTML document through the whitelist sanitizer, but I don't think we'll haev to do that.
Yeah, most things should be fixable via running the widgets through the sanitizer. But if a widget is known to be AMP-compatible to begin with, then I think we should bypass having to run it through sanitization.
We're working on a plan for this presently. I hope we'll have something to share by the end of this week.
So you'd essentially want to retain the paired mode? In that case, you'd really be having two separate themes entirely: one AMP and one non-AMP. We'd have to look at how we could do that. One thing you could try independently is dynamically switch between the active theme based on the presence of the |
Given I did not realize you intended to require
FYI, I am in a position I need to do something ASAP. My client was hoping for a solution last week but I put them off so I am hoping I can work on this today and Friday... Either I need to help you or I need to do a short term fork after which I don't know if I will be able to get the client to support me contributing after that since we'll be using the fork. But I really don't want to go there, so if you can empower me to get started...
For my specific use-case we have a commercial theme that is not one I want to deal with modifying (I was brought in for DevOps work but this AMP stuff came up, and since I was "the WordPress guy"...) and there is no appetite for a complete redo of the theme so we want to build a separate AMP theme for this project. Actually, my front-end guy is mostly finished with that. That said I bet a lot of other people will be in the same boat?
I'd rather not do that, for my use-case at least, and by "that" I mean two independent themes because then I have to manage them in two different repositories and we want to keep it all in one. What I would prefer is an I am not suggested this be the only way or even the preferred way, only that I would like it to still be possible using hooks as it is possible in the current plugin.
That would almost certainly be a nice to have for other use-cases, but it's not one that I actually need. Coming back around, any chance you can empower to get started sooner than later? |
It sounds like your project timeline is much more compressed than the timeline for the AMP plugin. We're looking at having something testable by January. It would probably be best for you to go ahead and fork, prototype things to deliver for the client project, and then we can merge in your changes into the AMP plugin. Continue to share what you're working on and we can talk about the architectural changes. I myself will be on vacation beginning next week until the new year, so I personally don't want to hold you up. However, @ThierryA can also give feedback in my absence.
What about this: If a theme simply does If a theme doesn't do But if a theme does this: add_theme_support( 'amp', array(
'template_path' => get_template_directory() . 'amp-templates/'
) ); Then the paired mode would be retained (with separate Maybe there should be some additional flags added to this theme support flag, like if there are specific queries supported. For example, let's say inside of add_theme_support( 'amp', array(
'template_path' => get_template_directory() . 'amp-templates/'
'active_callback' => function() {
return is_singular() || is_404();
};
) ); The naming should probably be tweaked more. For precedent, note the Any work you can do to iterate on these ideas into your project to prove them out would be helpful to confirm the approach for the AMP plugin. |
Understood. Moving forward is what I wanted but ideally I'd know what your team considers an acceptable direction so that my work does not veer off in a direction that your team finds unacceptable to merge.
Love it.
I may or may not need that, but will play it by ear and if I do need we can reconcile the ideas and names later if need be. If not it can be an enhancement from your team later, possibly with my help.
Absolutely. I'll get started. Thanks! |
As long as you keep the lines of communication open in your fork, hopefully we'll keep on the same page so that we can merge our respective ideas in January. Probably opening a PR from your fork back to this repo as you get started would be the best way to keep @ThierryA and myself aware of where you're going, and we can communicate via comments on the PR. We may not end up merging this PR specifically, but I expect we'll cherry-pick parts as we iterate with you on the feature that ends up landing in the plugin. |
We also should be gleaning the relevant parts from #668. |
Great idea. Will do that as soon as I have something worthwhile to commit.
My main concern is that I'll be able to use whatever the canonical path becomes, even if it means some simple changes on my end.
Will do. |
@westonruter I have been reviewing #688, and it seems overly complex added to an already complex plugin. What aspects of it are you considering to be relevant? |
It could be just the use of the |
@westonruter I am running into a situation where the current URL convention creates a problem. Adding Options I can think of: 1. Current Approach:
We could just say screw it, effectively disallow using 2. Subdomain:
There is also the nagging question if subdomain SEO that so many people are concerned about. 3. Root URL Slug:
This is better because it only disallows a root page from having 4. Query Param:
This works well but is less "clean" from a URL perspective. It also disallows any other use of 5. Special Character at End:
This is "clean" but it's ugly. It also adds complexity to category and page URL routing. 6. Special Character at Root:
Also ugly but avoids the complexity to category and page URL routing. Thoughts? Got any other suggestions? |
@mikeschinkel please refer to the support added for pages (#825): note that The same needs to be used for any non-singular queries. |
This has been implemented in |
We have a project where we need to build the entire site in AMP, and we are finding several of the architecture decisions for this plugin to make that more difficult than it needs to be.
It seems everything assumes routing through
template_redirect
and then to be served insideAMP_Post_Template->verify_and_include()
and making the$this
variable visible within the themes (and hence other AMP plugins are using it).When I discovered this is surprised me because I would have assumed it would follow WordPress architecture, hook
'template_include'
and provide template tags and other template-related functions (or maybe anWP_AMP
singleton to encapsulate all the AMP-related functionality.)Right now it seems that anything other that supporting other AMP-equivalent templates other than
single.php
would be a huge amount of work and I'm not even sure where someone would even start to add that support with this code base.Do you think the ship has sailed on the current architecture or that we could revisit this and move in the direction of supporting a more WordPress-compatible approach? I need to deliver something for a client and I am trying to decide if I should contribute to this project, fork it and modify it, or start from scratch.
The text was updated successfully, but these errors were encountered: