ampproject / amp-wp

Enable AMP on your WordPress site, the WordPress way.
https://wordpress.org/plugins/amp/
GNU General Public License v2.0
1.79k stars 382 forks source link

Allow users to add hreflang attribute for Internationalization #7877

Open milindmore22 opened 1 week ago

milindmore22 commented 1 week ago

Feature Description

AMP currently does not support the hreflang attribute on <link> tags with the attribute. This allows users to add internationalization to AMP pages to effectively and target specific language or regional audiences.

I will suggest adding a filter which will allow programs and users to customize the attribute as per thier requirements.

ref: https://amp.dev/documentation/examples/websites/guides/internationalization/

Acceptance Criteria

No response

Implementation Brief

No response

QA Testing Instructions

No response

Demo

No response

Changelog Entry

No response

westonruter commented 1 week ago

@milindmore22 Looking at the rules in that doc:

  1. Every canonical document must have a link tag with rel=amphtml pointing to its matching AMP document in the same language.
  2. Every AMP document must have a link tag with rel=canonical pointing to its matching canonical desktop document, again, in the same language.
  3. Every canonical document must have a link tag with rel=alternate and an hreflang attribute for each alternative language version of the canonical document.
  4. Every AMP document must have a link tag with rel=alternate and an hreflang attribute for each alternative language version of the AMP document.

We currently are doing (1) and (2). However, for (3) and (4) these are actually additional link tags, correct? So then do we actually need any filter at all? And what I mentioned to you about needing to remove_action() in the support topic actually is incorrect, right?

milindmore22 commented 1 week ago

Hello @westonruter yes. that's correct we also don't have to add hreflang attribute if there are rel=alternate are added.


      <link rel="alternate" href="https://amp.dev/static/samples/internationalization/alternate/index.mobile.html" />
      <link rel="alternate" hreflang="en" href="https://amp.dev/static/samples/internationalization/alternate/" />
      <link rel="alternate" hreflang="fr" href="https://amp.dev/static/samples/internationalization/alternate/fr/" />
      <link rel="alternate" hreflang="ja" href="https://amp.dev/static/samples/internationalization/alternate/ja/" />```