Changes in permalink structure in WordPress and how to apply to in-site links

I have some work for wordPress internationalization. Actually, I got good results.

Part of my code:

add_filter( ‘query_vars’, ‘queryi18n’ );

function queryi18n( $query_vars ){
$query_vars[] = ‘lang’;
return $query_vars;
}

/**********************/

add_action( ‘init’, ‘rule’ );

function rule() {
add_rewrite_rule(
‘^(en|fr|de|ru)/([^/]+)/?$’,
‘index.php?lang=$matches[1]&name=$matches[2]’,
‘top’
);
}

Result: localhost/en/hello-world it returns me a query.

$wp_query->query_vars[‘lang’] //en

Everything is fine up to this point. So I can run the persistent connection structure of WordPress properly with multi language support.

But there is a small detail:

If the LANGUAGE variable is checked in some way,
I need to add that language code to all INTERNAL links of WordPress except for external links.

So to summarize briefly:

If the browser -> “localhost/ru/hello-world” connection is opened,
I want all links within the site to be changed to “localhost/ru/…”.

All help suggestions are considered. Thanks.

Read more here:: Changes in permalink structure in WordPress and how to apply to in-site links

Leave a Reply

Your email address will not be published. Required fields are marked *