0

I'm adding a query var and creating a rewrite rule so I can enter the query variable nicely in the url. Here's the code:

function add_query_vars($aVars) {
    $aVars[] = "richter_redirect";
    return $aVars;
}
add_filter('query_vars', 'add_query_vars');


function add_rewrite_rules($aRules) {
    $aNewRules = array(
        'contact/([^/]+)/?$' => 'index.php?pagename=contact&richter_redirect=$matches[1]',
    );
    $aRules = $aNewRules + $aRules;
    return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');

So this way I can access https://www.richter.ca/contact/form/ being form the variable I can access in the page with:

$query_redirect = get_query_var('richter_redirect') 

An SEO analizes says I'm missing the self referencing hreflang, so I tried to manually update the hreflang using a script:

    <script>
        jQuery('link[hreflang="en"]').attr('href', jQuery('link[hreflang="en"]').attr('href') + '<?php echo $query_redirect; ?>');
        jQuery('link[hreflang="fr"]').attr('href', jQuery('link[hreflang="fr"]').attr('href') + '<?php echo $query_redirect; ?>');
        jQuery('link[hreflang="x-default"]').attr('href', jQuery('link[hreflang="x-default"]').attr('href') + '<?php echo $query_redirect; ?>');
    </script>

Looking at the source code everything looks fine, but the analyse is still saying self hreflang missing.

Any idea why this happens ?

Diezel
  • 43
  • 6

0 Answers0