I would like to ask for a hand to create a code that automatically generates hreflangs on the web page with identical names (ex. /page123.php).
For example the page www.example.it/page123.php has many versions in other languages.
Is it possible to automatically generate a code based on the link?
For example:
<link rel="canonical" href="https://www.example.it/page123.php" />
<link rel="alternate" href="https://www.example.it/de/page123.php" hreflang="de" />
<link rel="alternate" href="https://www.example.it/en/page123.php" hreflang="en" />
etc..
document.getElementById("url").innerHTML = window.location.href;
<p id="url"></p>