phpwordpressurlmeta-tagshreflang

Retrieve page permalink without GET parameters


This multilingual site generates url parameter at the end :

I want to precise the hreflang in the header, so I wrote :

<link rel="alternate" href="<?php echo get_permalink('') ;?>" hreflang="fr-fr" />

It works but then I get the url + the parameter, hence the hreflang is flase :

<link rel="alternate" href="https://www.example.fr/domaine/activite/industrie/?lang=fr" hreflang="fr-fr">
<link rel="alternate" href="https://www.example.fr/domaine/activite/industrie/?lang=fr" hreflang="en-fr">

Here is the result I want :

<link rel="alternate" href="https://www.example.fr/domaine/activite/industrie/?lang=fr" hreflang="fr-fr">
<link rel="alternate" href="https://www.example.fr/domaine/activite/industrie/?lang=en" hreflang="en-fr">

How can I retrieve separately the URL and the parameter ?


Solution

  • Tanks to Laken I could achieve what I wanted with a little change :

    Implementation :

    <link rel="alternate" href="<?php $wp_perma = get_permalink( '' );
    $lang = $_GET['?lang'];
    $wp_perma = str_replace( '' . $_GET['?lang'], '', $wp_perma );
    echo $wp_perma ;?>" hreflang="x-default" />
    

    As a result :

    <link rel="alternate" href="https://www.example.fr/domaines/activite/?lang=en" hreflang="x-default">
    

    So it's working fine for me.