Wordpress multiple slugs for a Custom Post Type

2019-02-26 06:46发布

A custom post type can be registered with one slug (e.g. products)

register_post_type('products', $args);

How can I add multiple slugs to the same Custom Post Type?

website_address.com/en/products/
website_address.com/fr/produits/
website_address.com/it/prodotti/

1条回答
戒情不戒烟
2楼-- · 2019-02-26 07:09

The rewrite argument for register_post_type() accepts an array. One of the array keys is slug. So you could i18n it like this:

register_post_type( 
    'products', 
    array (
        'rewrite' => array (
            'slug' => _x( 'products', 'URL slug', 'your_text_domain' )
        )
    )
);

Idea taken from here.

Ref: https://codex.wordpress.org/Function_Reference/register_post_type

查看更多
登录 后发表回答