How to remove blog prefix for custom post types in permalinks?

I have a client that used to have a static website and a blog powered from WordPress under the blog subdirectory. Now h

I have a client that used to have a static website and a blog powered from WordPress under the /blog subdirectory. Now he decided to move everything into WordPress so that he can also create and edit pages easily. However because the website is getting a lot of traffic and he already has likes, tweets and +1 in every blog post he wants to keep his blog under the website/blog. I thought it was as easy as heading over the permalinks and add /blog/%postname%/ in the permalink structure.

What the problem is right now is that I have a created a few custom post types to accommodate the needs of his content and custom post type's content resides now under the blog virtual directory.

How can I specify that only the blog posts and the blog categories must be under the /blog virtual directory and everything else can use the permalink structure of /%postname%/.

This is my custom post type

register_post_type( 'vm_products',
    array(
        'labels' => array(
            'name' => __( 'Products' ),
            'singular_name' => __( 'New product' ), //in the horizontal bar when you are logged in.
            'add_new' => __('Add new product'),
            'add_new_item' => __('New product'),
            'edit_item' => __('Edit product'),
            'new_item' => __('New product'),
            'view_item' => __('Show all products'),
            'search_items' => __('Search product'),
            'not_found' =>  __('No products found'),
            'not_found_in_trash' => __('No products found in trash'), 
            'parent_item_colon' => '',
            'menu_name' => 'Products'
        ),
    'public' => true,
    'has_archive' => true,
    'show_in_menu' => true, 
    'show_ui' => true,
    'supports' => array( 'title', 'custom-fields', 'editor', 'thumbnail'),
    'rewrite' => array('slug' => 'product'),
    'taxonomies' => array('vm_product_cats')
    )
);

I have a client that used to have a static website and a blog powered from WordPress under the /blog subdirectory. Now he decided to move everything into WordPress so that he can also create and edit pages easily. However because the website is getting a lot of traffic and he already has likes, tweets and +1 in every blog post he wants to keep his blog under the website/blog. I thought it was as easy as heading over the permalinks and add /blog/%postname%/ in the permalink structure.

What the problem is right now is that I have a created a few custom post types to accommodate the needs of his content and custom post type's content resides now under the blog virtual directory.

How can I specify that only the blog posts and the blog categories must be under the /blog virtual directory and everything else can use the permalink structure of /%postname%/.

This is my custom post type

register_post_type( 'vm_products',
    array(
        'labels' => array(
            'name' => __( 'Products' ),
            'singular_name' => __( 'New product' ), //in the horizontal bar when you are logged in.
            'add_new' => __('Add new product'),
            'add_new_item' => __('New product'),
            'edit_item' => __('Edit product'),
            'new_item' => __('New product'),
            'view_item' => __('Show all products'),
            'search_items' => __('Search product'),
            'not_found' =>  __('No products found'),
            'not_found_in_trash' => __('No products found in trash'), 
            'parent_item_colon' => '',
            'menu_name' => 'Products'
        ),
    'public' => true,
    'has_archive' => true,
    'show_in_menu' => true, 
    'show_ui' => true,
    'supports' => array( 'title', 'custom-fields', 'editor', 'thumbnail'),
    'rewrite' => array('slug' => 'product'),
    'taxonomies' => array('vm_product_cats')
    )
);
Share Improve this question edited May 14, 2012 at 13:54 fuxia 107k39 gold badges255 silver badges459 bronze badges asked May 14, 2012 at 13:03 nickastnickast 631 gold badge1 silver badge6 bronze badges 3
  • Can you show us the code you are using to setup your custom post types? There is an option in register_post_type called rewrite that allows you set the permalink options. – Joseph Leedy Commented May 14, 2012 at 13:16
  • I added the custom post type code I am using. My items are becoming /blog/product/... – nickast Commented May 14, 2012 at 13:46
  • This worked for me Remove slug from custom post type post URLs – Malki Mohamed Commented May 3, 2017 at 16:44
Add a comment  | 

2 Answers 2

Reset to default 20

Extend the 'rewrite' argument to suppress the first URL part:

        'rewrite' => array(
            'with_front' => false,
            'slug'       => 'product'
        )

But using just %postname% for different post types is really tricky and error prone. Avoid it.

In case you are using MULTISITE, then you need to just set the field in settings page:

Remove the blog slug from Wordpress Multisite root node

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744795710a4594191.html

相关推荐

  • How to remove blog prefix for custom post types in permalinks?

    I have a client that used to have a static website and a blog powered from WordPress under the blog subdirectory. Now h

    2天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信