I’m trying to setup an AMP installation for my current theme using the Google AMP Plugin.
I’ve configured AMP so it’s running in the Paired mode. Sage 9 (my theme) dosen’t seems to find the amp folder that holds my overrides for the template files. The AMP folder is in the resources folder but it dosen’t work. I’ve tried to use the “add_theme_support(‘AMP’)” function and specify the template_dir path with no luck … Somebody that knows how to do?
Hey @nahoj - from looking at the plugin docs and source a little bit and experimenting, it seems like when you choose “Paired” mode it just uses the theme’s normal templates, not AMP-specific templates, and you would have to use “Classic” mode for it to use the plugin’s template files (and allow you to override those template files in theme).
When I activated the plugin and chose “Paired” mode, http://mysite.com/post-name/?amp variants of my post URLs became available that served the AMP formatted version of the posts. For example, looking at the source you can see the AMP tags have been added and the site’s normal scripts have been removed.
Once I switched to “Classic” mode, it displayed using the plugin’s templates, and I was also able to override the files. By default, you’ll need to put them in resources/amp/, but you could filter that if you wanted to put them in views somewhere.
S’up! Hm, if you look here https://pre-prod.amp-wp.org/documentation/how-the-plugin-works/amp-plugin-serving-strategies/ under the section for “Paired Mode” then you can see that you can override templates based on the “template_dir” path… It should work with both… Maybe you have the same problem as me now? Paired mode dosen’t work correctly? It’s like when ur in Paired Mode AMP dosen’t find the AMP folder or just ignore it… Nothing happens.
My goal is to have “?/amp” in my url with overrides for my templates and therefor i’ve most use paired mode, right?
Given that knowledge, I would put your custom AMP templates in resources/amp/views/, essentially creating parallel template hierarchies for AMP and non-AMP content in resources/amp/views/ and resources/views/, respectively.
Another approach you might like better is to omit the custom template_dir option and just do this:
Then you put your AMP templates in resources/views/amp/.
Depending on how extensively you need to customize your AMP templates, you may find using their filters or using the is_amp_endpoint() conditional in your normal theme templates a shorter route.