最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Changes in permalink structure in WordPress and how to apply to in-site links

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论