ethercreative/seo

og:url and twitter:url referencing Blitz cache token

icreatestuff opened this issue · 2 comments

Description

We have a site that uses Ether SEO and the full-page caching Blitz plugin.

When Bltz is generating the cache it adds a token parameter to the URL which is being saved to the og:url and twitter:url meta tags within the SEO meta template because they use {{ craft.app.request.absoluteUrl }}. Based on this discussion on the Blitz repo and the warning provided in the Craft 4 class reference docs for this method it seems this isn't recommended.

The result of having the ?token=... parameter cached to those SEO tags is that the canonical URL that Facebook and Twitter/X are using is incorrect and results in no preview data (title, image description etc) being pulled through.

Is there an alternative to {{ craft.app.request.absoluteUrl }} that can be used?

Thanks

Additional info

  • Craft version: Pro 4.4.17
  • SEO version: 4.1.2
  • PHP version: 8.2.8
  • Database driver & version: MySQL 8.0.34
  • Other Plugins: Blitz 4.5.1

For now, I've ended up using a custom SEO meta template so I can override those tags using this instead {{ url(craft.app.request.fullPath) }} to remove any query strings from the URL. If there's a more elegant approach or a way to only exclude the ?token parameter but retain any other params that may exist I'm all ears.

Thanks for jumping on a fix for this so quickly @Tam really appreciated it.

It looks to be working pretty well for my use case so far, the only thing I'm wondering about is that my URLs are now left with a lonely ? at the end e.g. https://test-site.ddev.site/my-entry-page?. Is there a way to have that removed if there are no query string parameters left having removed the token parameter?

Thanks