8

I know that is not suggested and that there is lots of discussion about this argument out there. Unfortunally, after a week of trying and tests, I have not managed to remove the slug from my custom type yet. Here's the situation:

The url structure I need

  • post /blog/my-blog-post [ok!]
  • pages /parent-service/service [ok!]
  • portfolio /portfolio/my-first-work [ok!]
  • static /parent-static-page/static-page [<<<--- here is the problem]

My configuration

  • Wordpress 3.5.2
  • Custom type 'static': hierarchical; without any 'rewrite' rule.
  • Custom type 'portfolio': not hierarchical; 'rewrite' => array( 'with_front'=> false )
  • Permalink structure: /blog/%postname%/
  • As front page I set the static page 'blog'

The problem

  • post blog/my-blog-post [ok!]
  • pages /websites/dynamic-websites [ok!]
  • portfolio /portfolio/my-first-work [ok!]
  • static /who-i-am/terms [<<<--- here is the problem]

What I've tryed

Nothing

At the beginning, as expected, the url of the 'static' post "My test page" is /blog/static/my-test-page

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

I've removed the front from the url...good! Now I've /static/my-test-page

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

It doesn't remove the slug. I have /static/my-test-page yet.

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

It removes the slug! Now I have /my-test-page. Unfortunally all the pages return me a 404 error.

'Remove slug from custom post type' plugin

Even though it works only if my permalink structure is /%postname%, I've tried to install this plugin and change my permalink structure to do a test. It works, but unfortunally doesn't respect the hierarchical nature of my 'static' type.

The tutorial by Joakin Lim

It doesn't work. In particular, after adding function book_rewrite_rule() it says that my custom type now will be accessible from /my-test-page as well as /static/my-test-page, but it doesn't work for me. I can access only from /static/my-test-page. I've tryed also to apply all the tutorial, also doing some changements and tests, but without success

The tutorial from vip.wordpress

If I change 'event' with 'static' in both functions, I can access my page from blog/parent-page/my-test-page. If I add 'rewrite' => ( 'with_front'=>false ) everything brokes and I can access only from static/parent-page/my-test-page

Other solutions and tests

Unfortunally, with my actual reputation, I can't link more than two links. But I've tryed also the solution found in ryansechrest.com, shibashake.com and - of course - ALL the questions posted in this portal before. Off course every time I've flushed all the permalinks rules, visiting the setting page, saving the options, changing them twice and save them again, using the global $wp_rewrite; $wp_rewrite->flush_rules();. I've tryed lots of combination with the 'rewrite' array and the different solutions above.

Have you any suggestion?

2
  • 1
    Reviving a question that was asked soooo long ago (great question BTW). Did you ever find a solution? Could a solution be to use the default WP page types and use a custom page template?
    – Jen
    Commented Nov 23, 2016 at 19:32
  • Hi @guiniveretoo, I still not have found a solution. In my website I'm implementing an experiment: I will convert all my custom post types (portfolio, tools, info) and all posts in pages. In that manner I'll simplify structure and URLs. Then I'll specify pages with meta fields; also the front end will result simpler. Commented Nov 26, 2016 at 6:51

1 Answer 1

1

To accomplish this I always disable the slug when adding the custom post type, and add custom rewrites with the add_rewrite_rule function.

See also this codex page: https://codex.wordpress.org/Rewrite_API/add_rewrite_rule

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.