0.6.0 not working for pages
-
It says 0.6.0 now supports pages but even after i have turned this on in both amp and yoast it still is not working on pages. Are there some theme updates that need to be made to make this work for pages?
-
@gavpedz please share the URL for your install. Enabling post type support for Pages in the admin is the first thing. If your pages have custom page templates selected, then you’ll need to opt-in to AMP for each one.
Same problem on 2 websites I just tried. AMP for Pages is enabled in settings, and this site is using the native AMP template from the Automattic plugin: https://wp.me/PXOOz-6R. When adding /amp/ to the original URL, the page redirects to the canonical URL.
@pro99 If you edit the page in the admin, look in the Publish settings (metabox). There, above where the Update button is, you should see “AMP”, followed by either “Enabled” or “Disabled”. If it says Disabled, click on the Edit link and there should be a notice explaining why it is disabled. Please share what you see.
Aside: Pages and other hierarchical post types formulate the AMP version of the URL by adding ?amp instead of /amp/. The AMP version for any particular post/page can be found by looking for the amphtml link element on the non-AMP version of the post/page.
For others having the same problem. I had to enable amp per page. So go into each page and turn amp on. Be warned it’s not good at formatting some pages/themes. I use avada and page content is not shown in amp to well.
- This reply was modified 6 years, 10 months ago by gavpedz.
Pages with custom templates assigned are AMP-disabled by default for this exact reason: they may not be formatted properly. So it is better to opt-in when upgrading then have everything broken and have to opt-out.
The logic for determining whether AMP is supported for a post/page is
post_supports_amp()
: https://github.com/Automattic/amp-wp/blob/cceaffb9c67b7a40c401d36d1eed00e9d1666d72/includes/amp-helper-functions.php#L66-L106Yeah that makes sense. Thanks.
@westonruter, thanks for responding.
Turning on AMP for pages in the plugin settings enabled all pages for my site. AMP: Enabled.
I tried /privacy-policy/?amp and /privacy-policy?amp and they revert to canonical URL. My Chrome browser has the AMP extension where it shows green when an AMP version is available, and it’s grey.
@pro99 Hummm, I’m not sure then. Here is where the redirect is being performed in the code: https://github.com/Automattic/amp-wp/blob/cceaffb/amp.php#L181-L183
That is where I’d be looking to see what is going wrong. If you are comfortable editing PHP I’d recommend you try debugging there and in the
post_supports_amp()
function. Otherwise, I could try to debug it for you but I’d need access to your environment. In that case, probably best for you to connect with me over email.Thanks @westonruter for the offer to help. Before that, I am checking our Nginx server rewrite rules with our host. I was able to successfully activate Pages on an old site that runs on a different host (Apache), while all our sites on Nginx are having this unintended redirect. What’s odd is that AMP for posts has been working flawlessly so far.
It seems that /amp/ and ?amp are triggering different behaviors. Why use ?amp for pages? In general, URL extensions with ?XXX relate to marketing tracking codes or unwanted and random strings generated by bots in pageview reports.
@pro99 Thanks, that’s helpful.
The use of the
?amp
query var is required for pages and other such hierarchical post types in order to prevent ambiguity from happening. Consider you have a website about guitars and you publish pages about your favorite accessories, including which amp you like the most. So you publish a page with the URL path/guitars/favorites/amp/
. If the/amp/
endpoint were used for pages, then WordPress would not know whether you are trying to get the AMP version of the Favorites page or the non-AMP version of the page about your favorite amp.Here is the logic behind when a query var is chosen instead of an endpoint slug: https://github.com/Automattic/amp-wp/blob/4744f2d/includes/amp-helper-functions.php#L37-L38
So you can see that
?amp
is used when pretty permalinks aren’t enabled (of course), when a hierarchical post type is used, or when there are other query vars present.We confirmed with the Google search team that using
?amp
is perfectly valid from their side of things.Possibly caused by the Glue for Yoast & AMP plugin having it’s own options to toggle from WP admin dashboard -> SEO -> AMP:
https://i.imgur.com/qHqXngF.pngEdit: Oh I see you turned them on already, never mind.
- This reply was modified 6 years, 10 months ago by websevendev.
If using ?amp is perfectly valid, why they are not displayed in
https://www.google.com/webmasters/tools/accelerated-mobile-pages@roma77 It is valid but it is not the default for posts. What matters is what the
link rel=amphtml
element in the canonical version of your post says is the URL for your AMP content. To force the URL that is shown in thislink
tag to tell Google to always look for?amp
instead of/amp/
, add this code to your custom theme or plugin:add_filter( 'amp_get_permalink', function( $url, $post_id ) { return add_query_arg( AMP_QUERY_VAR, '', get_permalink( $post_id ) ); }, 10, 2 );
That will force
?amp
to be used exclusively instead of switching between/amp/
and?amp
.
- The topic ‘0.6.0 not working for pages’ is closed to new replies.