Add filter to exclude links on an individual basis from AMP-to-AMP linking #4913
Labels
Changelogged
Whether the issue/PR has been added to release notes.
WS:Core
Work stream for Plugin core
Milestone
Feature description
AMP-to-AMP linking was introduced in #1389 via #3627 and enabled by default in Transitional mode or in Reader mode via the
amp_to_amp_linking_enabled
filter. Then in #3689 via #4146 individual links can be disabled from AMP-to-AMP linking in these ways:amp_to_amp_excluded_urls
to add all URLs that should be excluded from AMP.noamphtml
link relation to links on the page.However, this has turned out to not be very convenient. Given existing post content that has a bunch of links in it, it is difficult to use the
the_content
filter to parse out the links and either add them toamp_to_amp_excluded_urls
or inject anoamphtml
link relation. In other cases, where the links are not inthe_content
(e.g. in the template itself), this may not be possible at all, forcing a developer to create a custom sanitizer to inject thenoamphtml
link relations.What would be the most convenient is if there was a filter like
amp_to_amp_linking_element_excluded
which was passed was passed a boolean value to control the exclusion, along with the specific link context. For example:The initial value for
$excluded
would reflect whether or not$url
was among theamp_to_amp_excluded_urls
or if the link had anoamphtml
link relation. But then a plugin could have fine-grained control over whether a link points to another AMP page. For example, if you wanted to quickly exclude categories from AMP-to-AMP linking, you could do:At the time AMP-to-AMP linking was introduced, the ability to filter links in this way was not doable since the arguments being passed into the sanitizers needed to deterministically result in a given output, since the sanitizer args were used as the cache key for the “post-processor cache”. This is no longer a concern, however, since the post-processor cache was eliminated in #4391 due to being ineffectual (see #4178). So now we can safely
apply_filters()
inside of sanitizers.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation brief
QA testing instructions
Demo
Changelog entry
The text was updated successfully, but these errors were encountered: