Skip to content
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

Allow opting-out of AMP-to-AMP links, ensure 'Exit Reader Mode' link is non-AMP #4146

Merged
merged 20 commits into from
Jan 24, 2020

Conversation

kienstra
Copy link
Contributor

@kienstra kienstra commented Jan 21, 2020

Summary

This allows opting out of AMP-to-AMP links via the filter 'excluded_links_from_amp_to_amp' or adding rel="noamphtml" to the <a>.

Rel attribute

<a href="https://am.test/?p=195" rel="noamphtml">To non-AMP</a>

...will produce a link to a non-AMP URL, with the rel stripped:

<a href="https://am.test/?p=195">To non-AMP</a>

Filter

// Excludes URLs from having AMP-to-AMP links.
add_filter(
	'amp_to_amp_excluded_urls',
	static function() {
		return [
			'https://am.test/?p=195',
			'https://am.test/?p=199',
		 ];
	}
);

'Exit Reader Mode' Link

Even with add_filter( 'amp_to_amp_linking_enabled', '__return_true' );, the 'Exit Reader Mode' link will now go to non-AMP:

filter-mode

Fixes #3689

Checklist

  • My pull request is addressing an open issue (please create one otherwise).
  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

As Weston suggested,
this forces links to non-AMP.
Even if add_filter( 'amp_to_amp_linking_enabled', '__return_true' );
is present, this should still go to non-AMP.
When in Reader or Transitional mode,
links to the same origin will usually be
to AMP.
But this filter enables passing URLs
that will link to non-AMP, not AMP.
The if block only ran if the previous
block didn't, so an elseif block
probably makes sense here.
@googlebot googlebot added the cla: yes Signed the Google CLA label Jan 21, 2020
It's not very clear what these are testing
without the comments.
There's no need to store this in a variable,

So simply move the boolean to the conditional.
This is clearer that it's in the AMP plugin,
as the beginning serves as a sort of prefix.
kienstra and others added 4 commits January 21, 2020 15:58
Commit Weston's suggestion

Co-Authored-By: Weston Ruter <[email protected]>
Pass a 3rd argument of true to
array_search() so that Travis passes.
Now that it's changed to noamphtml,
update this in the unit tests also.
@kienstra kienstra changed the title [WIP] Allow opting-out of AMP-to-AMP links, ensure 'Exit Reader Mode' link is non-AMP Allow opting-out of AMP-to-AMP links, ensure 'Exit Reader Mode' link is non-AMP Jan 22, 2020
templates/header-bar.php Outdated Show resolved Hide resolved
includes/amp-helper-functions.php Show resolved Hide resolved
includes/amp-helper-functions.php Outdated Show resolved Hide resolved
includes/amp-helper-functions.php Outdated Show resolved Hide resolved
includes/amp-helper-functions.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-link-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-link-sanitizer.php Outdated Show resolved Hide resolved
kienstra and others added 9 commits January 22, 2020 23:17
The rel value was changed to noamphtml,
so it should be reflected here also.

Co-Authored-By: Weston Ruter <[email protected]>
Using Weston's suggestion
in the pull request.
As Weston pointed out,
this is filtering URLs.
These are not really links,
they're URLs.
As Weston mentioned,
this shouldn't be used in comparison.
As Weston mentioned,
this didn't have one.
Do npm run lint:php:fix
to fix some of these.
@westonruter westonruter added this to the v1.5 milestone Jan 23, 2020
@westonruter westonruter merged commit a2763d8 into develop Jan 24, 2020
@westonruter westonruter deleted the update/amp-to-amp-exclusion branch January 24, 2020 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Signed the Google CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem with AMP to AMP navigation
3 participants