How to implement a different permalink structure for custom post type?

Tried to use this plugin, but it doesn’t seem to be working: https://wordpress.org/plugins/custom-post-type-permalinks/

I’m setting a permalink structure for by blog posts in settings>permalinks like so: /blog/%postname%

I also have a custom post type called “project”, where I want the structure to be /our-work/%postname, but instead the /blog part gets prepended here too. How can I keep a separate permalink structure for this custom post type?

Here’s the register_post_type function:

register_post_type('project', array(
    'public' => true,
    'custom' => true,
    'show_ui' => true,
    'supports' => array('title','editor','revisions'),
    'labels' => array(
        'name' => 'Projects',
        'singular_name' => 'Project',
        'add_new_item' => 'Add New Project',
        'edit_item' => 'Edit Project'
    ),
    'menu_icon' => 'dashicons-portfolio',
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_rest' => true,
    'rewrite' => array(
        'slug' => 'our-work', 
        'with_front' => true
    ),
    'has_archive' => true,
    'show_in_graphql' => true,
    'graphql_single_name' => 'project',
    'graphql_plural_name' => 'projects',
    'cptp_permalink_structure' => '%post_id%'
));

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Just set the with_front argument to false:

register_post_type( 'project', array(
    ... your args.

    'rewrite' => array(
        'slug'       => 'our-work',
        'with_front' => false
    ),

    ... your args.
) );


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x