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?
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