Set permalinks for custom post types in WordPress to root
P粉267885948
P粉267885948 2023-08-09 11:35:09
0
1
483
I created a custom post type to organize a specific type of page, but since my WordPress permalinks are set to <code>/blog/%postname%/</code>, this new custom post type The permalink is <code>/blog/new-post-type</code>. I don't want to remove <code>/blog/</code> from the site's permalink settings because we use it in blog posts. How to remove <code>/blog/</code> from a new post type so that it acts like a permalink to the WordPress default page, i.e. <code>www.website.com/name-of-page/< ;/code>?
P粉267885948
P粉267885948

reply all(1)
P粉476883986

register_post_type()The rewrite parameter of the function has a with_front parameter. When set to false, it will not be used in the fixed link Add a prefix to the structure.

register_post_type( 'cpt', array(
    'rewrite' => array(
        'with_front' => false,
    )
);

The above code will prevent /blog/ from appearing in CPT's post URL, but I don't know if that means the URL will work in the root directory.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template