admin管理员组文章数量:1130349
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
1 Answer
Reset to default 1All 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' );
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
1 Answer
Reset to default 1All 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' );
本文标签: phpWordPress custom slug (endpoint) and compare all links
版权声明:本文标题:php - WordPress custom slug (endpoint) and compare all links 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749198250a2331356.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论