Changing slug of all posts


I have a site with around a dozen custom post types. I’d like to change the default post type so that it’s URL has a slug of /news/.

In my functions file I have:

    add_action( 'init', 'change_post_object' );
    // Change dashboard Posts to News
    function change_post_object() {
        $get_post_type = get_post_type_object('post');
        $labels = $get_post_type->labels;
        $labels->add_new = 'Add News Item';
        $labels->add_new_item = 'Add News Item';
        $labels->edit_item = 'Edit News';
        $labels->new_item = 'News';
        $labels->view_item = 'View News Item';
        $labels->search_items="Search News";
        $labels->not_found = 'No News found';
        $labels->not_found_in_trash="No News found in Trash";
        $labels->all_items="All News";
        $rewrite = $get_post_type->rewrite;
        $rewrite->slug = 'news-events/news';

… Which all works apart from the rewrite of the slug.

Lots of posts suggest just changing the permalink structure on the Permalinks page from /%postname%/ to /news/%postname%/. This works – but breaks all the other custom post types.

How can I do this please?!

JohnG 2 months 2021-11-30T10:21:45-05:00 0 Answers 0 views 0

Leave an answer