WordPress: Custom Post Type with different base URL from Standard Post Type

I created a custom post type called Products alongside by blog. My blog Archive URL is

www.mywebsite.com/blog

and the blog posts looks like

Read More
www.mywebsite.com/blog/postName.

My Products Custom Post Type URL looks like

www.mywebsite.com/blog/products. 

I want would like to remove the blog directory from the url and make it look just like

www.mywebsite.com/products/productName

I can do this by removing the /blog/%postname% from my permalinks in WordPress, but then my blog posts look like: www.mywebsite.com/postName, without the blog directory.

How do I give my custom post types a clean URL without the blog directory?

Related posts

1 comment

  1. Maybe it helps you. Do something like that —

    $labels      = array(
                    'name'               => $plural_title,
                    'singular_name'      => $title,
                    'add_new'            => __( 'Add New', 'adeq' ),
                    'add_new_item'       => __( 'Add New', 'adeq' ) .' '. $title,
                    'edit_item'          => __( 'Edit', 'adeq' ) .' '. $title,
                    'new_item'           => __( 'New', 'adeq' ) .' '. $title,
                    'all_items'          => __( 'All', 'adeq' ) .' '. $plural_title,
                    'view_item'          => __( 'View', 'adeq' ) .' '. $title,
                    'search_items'       => __( 'Search', 'adeq' ) .' '. $plural_title,
                    'not_found'          => $plural_title . __( ' not found', 'adeq' ),
                    'not_found_in_trash' => $plural_title . __( ' not found in Trash', 'adeq' ),
                    'parent_item_colon'  => '',
                    'menu_name'          => $plural_title
                    );
    
                if ( !empty( $args['labels_override'] ) ) {
                    $labels = wp_parse_args( $args['labels_override'], $labels );
                }
    
                $defaults = array(
                    'labels'             => $labels,
                    'public'             => true,
                    'publicly_queryable' => true,
                    'show_ui'            => true,
                    'show_in_menu'       => true,
                    'show_in_nav_menus'  => true,
                    'query_var'          => true,
                    'has_archive'        => true,
                    'hierarchical'       => false,
                    'menu_position'      => null,
                    'menu_icon'          => null,
                    'supports'           => array( 'title', 'thumbnail', 'editor' )
                    );
    
                $args = wp_parse_args( $args, $defaults );
                $this->post_types[ $post_type ] = $args;
            }
        }
    

    Your Permalink will show like —

Comments are closed.