最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - WordPress custom slug (endpoint) and compare all links

matteradmin8PV0评论

I work on the one i18n function. It will work with subdir. For example: eg/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/en
eg/page/en
eg/post(hello-world)/fr
eg/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/example/en" >Example</a>
<a href="eg/05/11/2018/en" >Example</a>
<a href="eg/category/news/en" >Example</a>

elseif($_COOKIE['lang'] == 'de') :

<a href="eg/05/11/2018/de" >Example</a>
<a href="eg/tags/computer/de" >Example</a>

endif;

I work on the one i18n function. It will work with subdir. For example: eg/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/en
eg/page/en
eg/post(hello-world)/fr
eg/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/example/en" >Example</a>
<a href="eg/05/11/2018/en" >Example</a>
<a href="eg/category/news/en" >Example</a>

elseif($_COOKIE['lang'] == 'de') :

<a href="eg/05/11/2018/de" >Example</a>
<a href="eg/tags/computer/de" >Example</a>

endif;
Share Improve this question edited Nov 7, 2018 at 22:29 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Nov 7, 2018 at 21:39 l6lsl6ls 3311 gold badge3 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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' );
Post a comment

comment list (0)

  1. No comments so far