Home  >  Q&A  >  body text

Set permalinks for custom post types in WordPress to root

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粉267885948P粉267885948459 days ago461

reply all(1)I'll reply

  • P粉476883986

    P粉4768839862023-08-10 10:28:03

    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.

    reply
    0
  • Cancelreply