@tangrufus Would you mind telling me where exactly in the plugin’s files can I manually add the post’s AMP URL so it’s purged from Cloudflare as well? Cheers.
Will AMP be supported out of the box?
Unlikely. Because different AMP plugins give different urls. Most importantly, using Cloudflare cache everything rules on AMP urls is unnecessary because they are cached by Google. I am not seeing any issue with AMP on the sites I manage.
Despite all that, Sunny allows you to extends it.
Use the sunny_post_related_urls filter.
Example: https://github.com/TypistTech/sunny-purge-extra-urls-example/blob/4bea120aa0210b1fd373ef8639c6c9675c19daf1/sunny-purge-extra-urls-example.php#L34-L58
Thanks for getting back to me, @tangrufus!
I think the most common URL scheme for AMP is adding /amp/ to the end of the post’s URL. I’ve seen rare uses of ?amp, but those are the only two.
Google does indeed cache the AMP pages when accessed via its search, but we see quite a lot of visits going directly to our full /amp/ URLs. I think a few mobile Twitter clients, of example, look for that by default. So that doesn’t go through Google’s cache, and it’s still important to use the “Cache Everything” Cloudflare rule.
On the filter, I’m not a very experienced programmer, so I’m not sure how to do it. I know this example below is wrong, but that’s the main idea:
add_filter('sunny_post_related_urls', 'extraurlsunny', 10, 2);
function extraurlsunny(array $urls, WP_Post $post): array {
$urls['extra-related-urls-filter'] = [
$post->permalink . '/amp/'
];
return $urls;
}
What’s the right way to do it? Thanks a lot!
Technically, AMP url can be anything you want:
<link rel="amphtml" href="https://www.example.com/anything-i-want.html">
Take https://example.com/faq as an example, structures I have seen:
Your code should work. Check it on “Sunny” –> “Debuggers” –> “Enter a Post ID”
-
This reply was modified 8 years, 2 months ago by
Tang Rufus.
I see what you mean about the URLs, @tangrufus. No worries.
So the code doesn’t work yet. I’m not sure $post->permalink is a thing.
Sunny is just considering the /amp/ part, it’s not prepending the post’s permalink URL there.
Maybe get_permalink($post).
If you need help for coding, hire a freelance developer is your best choice.
That worked! I just had to remove the first / from /amp/, as the full permalink URL already includes a / in the end.
Thanks a lot.