【问题标题】:Translate custom post type slug翻译自定义帖子类型 slug
【发布时间】:2021-08-21 12:49:16
【问题描述】:

我正在使用 Wordpress 5 和 WPML。 我有很多自定义类型。 每个自定义类型都有自己的 slug。

我的网站是英文和法文的

示例:

我需要用法语翻译城市和国家:

如何翻译 slug ?

自定义类型示例:

$rewrite = array(
        'slug'                  => 'city',
        'with_front'            => true,
        'pages'                 => true,
        'feeds'                 => true,
    );
    $args = array(
        'label'                 => __( 'Les villes', 'test' ),
        'description'           => __( 'Les villes', 'test' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'thumbnail' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'menu_icon'             => 'dashicons-admin-home',
        'show_in_admin_bar'     => false,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'rewrite'               => $rewrite,
        'capability_type'       => 'page',
        'show_in_rest'          => true,
    );

    register_post_type( 'villes', $args );
}
add_action( 'init', 'villes_post_type', 0 );

【问题讨论】:

    标签: wordpress advanced-custom-fields wpml


    【解决方案1】:

    由于您使用的是 WPML,因此您可以使用 WPML 插件来实现这一点。

    1. 安装并激活“WPML 字符串翻译”插件。
    2. 转到 WPML -> 设置
    3. 在“Slug translations”部分下,选中“Translate custom post and taxonomy base slugs (via WPML String Translation)”。
    4. 在同一页面上,向下滚动,在“帖子类型翻译”下,找到您的自定义帖子类型的名称。
    5. 选中“为 [post type name] 设置不同语言的不同 slug”
    6. 输入每种语言的已翻译帖子类型 slug。
    7. 点击“保存”按钮。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-08
      • 2021-10-17
      • 2018-11-23
      • 2017-01-31
      • 2017-09-19
      • 2014-11-10
      • 1970-01-01
      • 2016-12-04
      相关资源
      最近更新 更多