WordPress custom slug (endpoint) and compare all links

I work on the one i18n function. It will work with subdir. For example: eg.com/hello-world/en

For this I’m support EP_ALL for the wp custom endpoints.

function lang_add_endpoints(){
add_rewrite_endpoint(‘en’, EP_ALL);
add_rewrite_endpoint(‘de’, EP_ALL);
}
add_action(‘init’, ‘lang_add_endpoints’);

For example:

eg.com/en
eg.com/page/en
eg.com/post(hello-world)/fr
eg.com/10/11/2018/de
and more…

It is well done.
Now can i how to add “/en/ or /de/ or /any/” slug all WP links if the query has “en”.

For example:

I have COOKIE: (I have an idea just i say for my quest)

if($_COOKIE[‘lang’] == ‘en’) :

<a href=”eg.com/example/en” >Example</a>
<a href=”eg.com/05/11/2018/en” >Example</a>
<a href=”eg.com/category/news/en” >Example</a>

elseif($_COOKIE[‘lang’] == ‘de’) :

<a href=”eg.com/05/11/2018/de” >Example</a>
<a href=”eg.com/tags/computer/de” >Example</a>

endif;

Read more here:: WordPress custom slug (endpoint) and compare all links

Leave a Reply

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