• Hi, I am working on a site where we changed the permalink stucture in the settings so that the blog posts have this structure

    /blog/%postname%/

    I created a custom post type and set this attribute in the register_post_type

    ‘rewrite’ ? => array( ‘slug’ => ‘swag’ ),

    however the archive pages show up as /blog/swag and the singles are like /blog/swag/%postname%/

    Is there any way to override the setting in the permalink setting page for the custom post type so that the archive is just /swag and the individual pages are /swag/%postname%/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Something like this may get you what you want:

    function update_permalink_structure($args, $post_type) { if ($post_type == 'your_custom_post_type') { $args['rewrite']['slug'] = 'new-slug'; } return $args; } add_filter('register_post_type_args', 'update_permalink_structure', 10, 2);

    Best of luck!

    Thread Starter shuangmiles

    (@shuangmiles)

    Thank, it didn’t work initially but I realized that what I had originally

    ‘rewrite’ ? => array( ‘slug’ => ‘swag’ ),

    worked it’s just that I had to re-save the permalink settings……yeah gigantic face palm but hopefully that helps anyone that might run into that too.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Looking to override permalink structure for custom post type’ is closed to new replies.