I made this Website that uses anchor links in two internal pages. It´s a multilingual site, using PolyLang. The language selector is located in a floating menu at the upper right of the Website.
The owner of the site wants to use the reciprocal page functionality of the language selector. That means; in any page in English, you click on the Language Selector (Spanish) that will take you to the equivalent (reciprocal) page acording to the child menus from the parent menu item ACTIVITIES.
- window.location.replace to substitute the canonical URL with the one including the anchor #outdining at the end of the URL.
- window.location.reload to refresh the page and make it go the anchor link.
It works fine.
For example, the page is located in the anchor #cycling; then you click in the upper right floating menu “Español” and the corresponding URL will be /es/actividades/; then the #cycling anchor needs to be added at the end.
The code I used for the working page is below:
Please help figuring out the code to dynamically add the anchor displayed in the URL to the translated URL end.