1

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, how can I 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;
1

All of the API functions that generate links have filters to let you alter the output. Here's a quick example that covers most of them:

function wpd_endpoint_links( $url ){
    if( isset( $_COOKIE['lang'] ) ){
        $url = $url . $_COOKIE['lang'] . '/';
    }
    return $url;
}
add_filter( 'post_link', 'wpd_endpoint_links' );
add_filter( 'page_link', 'wpd_endpoint_links' );
add_filter( 'post_type_link', 'wpd_endpoint_links' );
add_filter( 'attachment_link', 'wpd_endpoint_links' );
add_filter( 'term_link', 'wpd_endpoint_links' );
add_filter( 'author_link', 'wpd_endpoint_links' );
add_filter( 'post_type_archive_link', 'wpd_endpoint_links' );
add_filter( 'day_link', 'wpd_endpoint_links' );
add_filter( 'month_link', 'wpd_endpoint_links' );
add_filter( 'year_link', 'wpd_endpoint_links' );

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.