url rewriting – How to translate slugs in custom post types or making them dynamic?

Question

How can we translate the rewrite slug in custom post types? Or making them dynamic with regex?

For example:

function news_init() {
    $args = array(
        'labels' => array(
            'name' => __('News (Pages)'),
            'singular_name' => __('News'),
            'all_items' => 'All News'
       ),
        'public' => true,
        'rewrite' => array(
            'slug' => 'news',
            'with_front' => true
        ),
    register_post_type('news', $args);
}
add_action('init', 'news_init');

That 'slug' => 'news', needs to be dynamic for different translation sites. Can we do it without any plugin?

0
laukok 2 months 2021-06-10T20:31:42-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse