3

This question has been asked so many times, and i have viewed every answer in this meta, and outside.

Still none are functioning in Wordpress 4.9.5 (latest version). The enhancement asked 3 years ago is still waiting: https://core.trac.wordpress.org/ticket/34136#ticket

How to remove the Custom Post Type slug name from the url, without creating issue to previous posts or pages?

I've tried the following solutions: https://wordpress.stackexchange.com/a/204210 - 404 page https://kellenmace.com/remove-custom-post-type-slug-from-permalinks/ - 404 page http://www.codeinhouse.com/remove-slug-from-custom-post-type-in-wordpress/ - 404 page

1 Answer 1

1

Change permstruct for your CPT.

add_action( 'init', function() {
    add_permastruct( 'tvshow', '/custom_home_page/%tvshow%');
}, 11);

However, this is a complex question and can involve different steps to make it work in different ways.

P/S/ don't forget to flush url rules.

5
  • Can you explain the solution?
    – Benjamin
    Apr 23, 2018 at 7:58
  • You changing permstruct of your post type. You adding any base you want which I assume your desired state, a changed permstruct will care about generated rewrite rules and future links generation. Apr 23, 2018 at 8:05
  • I don't want any base. What is the rule to delete the slug before the %postname%?
    – Benjamin
    Apr 23, 2018 at 8:57
  • I don't recommend to do this. In such case, it will collide with pages. You need to learn first to use rewrite_rules, once you master it you will be able to create own structure. Even one you want to have. Apr 23, 2018 at 9:22
  • The purpose of this question is to do this.
    – Benjamin
    Apr 23, 2018 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.