Mobile Redirection

Originally AMP stood for “Accelerated Mobile Pages”, but since its inception AMP has evolved by leap and bounds and that acronym does not apply anymore. AMP is a fully responsive Web framework and AMP-powered sites can bring a user-first experience to users on both desktop and mobile. This scenario is enabled by configuring the AMP plugin in Standard mode, and it corresponds to the ideal scenario. AMP-first FTW!

As the WordPress ecosystem evolves towards ubiquitous AMP compatibility, scenarios where the plugin is configured with the Transitional or Reader modes are still frequently demanded and chosen by users. And since it is on mobile devices where an AMP experience is most important, site owners want to direct mobile visitors to the AMP version of their site, as they progressively traverse the path towards full AMP compatibility and having their site all in AMP.

This capability is only available when a site is in Transitional or Reader modes (i.e. paired AMP modes) since in Standard mode there is no separate AMP version to redirect to.

Enabling mobile redirection #

Mobile redirection can be enabled in the first option in the Advanced Settings section of the Settings screen:

With the toggle setting on, users visiting your site from mobile devices will be redirected to get the experience provided by your AMP pages.

AMP-to-AMP linking #

When mobile redirection is enabled, AMP-to-AMP linking is automatically enabled. This ensures that navigating around the AMP version of the site will not result in the user constantly having to wait for a redirect from the non-AMP to the AMP version. To facilitate indicating which links should be rewritten to point to the AMP versions, an amp_to_amp_linking_element_excluded filter is added which allows opting out of AMP-to-AMP linking on a per-link basis; previously an array of all such link URLs had to be supplied via the amp_to_amp_excluded_urls filter. Any links which are excluded from AMP-to-AMP linking will automatically include ?noamp=mobile added to them to prevent any possible undesirable redirection to the AMP version. 

In addition to AMP-to-AMP linking, the non-AMP version of the page now includes a rel=alternate link pointing to the AMP version alongside the existing rel=amphtml link.

AMP-non-AMP linking #

When on the AMP version, a new “Exit mobile version” link appears in the footer of the page. The link text of which can be filtered via amp_mobile_version_switcher_link_text and the default GitHub-inspired gray styling can be turned off via add_filter( 'amp_mobile_version_switcher_styles_used', '__return_false' ). The link takes the user to the same URL but with ?amp replaced with ?noamp=mobile. This query parameter prevents redirection back to the AMP version and it suspends automatic redirection for the remainder of the browsing session. To return to the AMP version, a similarly-styled link in the footer of the non-AMP version of the page is added for mobile visitors.

Notice that the old “Exit Reader Mode” link which previously appeared in the header of the legacy Reader mode templates has been eliminated in favor of this new footer link.