php - 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( 'quer

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745202907a4616433.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信