I'm trying to have some dynamic URL. I made a custom tag for my permalink to show the language of the blog, but i'm facing an issue with dynamic URL. The problem is that it only consider 'fr' in my path. Which is not dynamic at all. here is my code

add_filter('post_link', 'language_permalink', 10, 3);

add_filter('post_type_link', 'language_permalink', 10, 3);

$url_fr = 'ac01psrvweb01fr.com';
$url_en = "ac01psrvweb01.com";
function language_permalink($permalink, $post_id, $leavename) {
        $url_host = $_SERVER['HTTP_HOST'];
        if (strpos($permalink, '%language%') === FALSE) return $permalink;

        $post = get_post($post_id);
        if (!$post) return $permalink;

        $terms = wp_get_object_terms($post->ID, 'language');
        if ( !is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
                $taxonomy_slug = $terms[0]->slug;
        if (strcmp($url_en, $url_host) == 0 ? $taxonomy_slug = 'fr' : $taxonomy_slug = 'en');

        return str_replace('%language%', $taxonomy_slug, $permalink);
function custom_rewrite_tag(){
        add_rewrite_tag('%language%', '([^&]+)');
add_action('init', 'custom_rewrite_tag', 10, 0);

So i Would like that when we hit the URL ac01psrvweb01fr.com it add to the path /fr/ and for the url ac01psrvweb01v.com it add to the path english.

I hope i'm clear and my code is too. If you have any questions ask for further informations. Thanks in advance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.