12

Seriously, why 'with_front' => false does not work as it should be? It is supposed to remove TAXONOMY BASE NAME and my question is why it does not work?

I just dont want the taxonamy base slug appear in my URL and codex says 'with_front' => false should help but it does not. Leaving the slug empty like 'slug'=> '' generates 404 error.

register_taxonomy("tax_categories", array("products"), array(
    "hierarchical" => true,
    "label" => "Categories",
    "singular_label" => "Category",
    "show_ui" => true,
    'update_count_callback' => '_update_post_term_count',
    "rewrite" => array(     
        'with_front' => false,      
        'hierarchical' => true      
        )
    ));

This issue supposed to be fixed http://core.trac.wordpress.org/ticket/16807

Please help to understand that. Thank you.

5
  • 3
    Try and Go to your settings-->permalinks and click save, or flush the rewrite rules.
    – Wyck
    Commented Sep 11, 2011 at 2:27
  • 2
    As Manny said, with_front does not remove the taxonomy base name. I assume you want to convert the link format from /tax-categories/banana/ to /banana/? There was a question about this (it's quite complicated), but I can't find it right now.
    – Jan Fabry
    Commented Sep 12, 2011 at 5:59
  • thats is exactly what is needed.
    – Alex
    Commented Sep 12, 2011 at 8:48
  • The problem is you sorta need the taxonomy name in there so that WordPress knows the next thing is the taxonomy term. The only way I know to do it is if you create a completely custom permalink. Do you know what you want your permalink to look like? Commented Sep 12, 2011 at 12:14
  • The other question @JanFabry refers to might be this one: wordpress.stackexchange.com/questions/21076/…
    – Tim Malone
    Commented Mar 8, 2018 at 3:29

3 Answers 3

12

To remove the taxonomy base name, you can use:

'rewrite' => ['slug' => '/', 'with_front' => false]

However, this will make your (basic post type) posts go 404, if you have permalinks set to http://example.com/sample-post/. It seems you cannot have both custom taxonomy and posts reside in the root. Therefore you would go to Permalinks settings and set Custom structure , e.g. /blog/%postname%/.

One more note

A side effect is that your CPTs would have this "front", too, e.g. blog/products. This is where 'with_front' => false comes to play. It's designed to get you rid of the custom structure start. So in your product type registration, you would have:

register_post_type( 'products',  array(
           'rewrite' => array(
                'slug' => 'products',
                'with_front' => false
            ),
            /* ... */
));
1
  • Someone flagged your answer. But I found it appropriate. Commented May 3, 2019 at 2:11
11

All with_front does is toggle whether or not a taxonomy link can have something else in front of it ie extra permalink stuff from the permalinks options page. For example with_front set to true makes this possible:

blah.com/2011/09/tax/term

with it set to false, all you can do is:

blah.com/tax/term
1
  • 3
    I see... does not help though. How to remove the /TAX/ part from taxonomy?
    – Alex
    Commented Sep 12, 2011 at 8:50
6

Use the code below:

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

Notice that when you rewrite the slug that the default page template is opened, when you go to the taxonomy page.

4
  • 3
    In addition to what @tf said, also please explain why your code provides a solution.
    – shea
    Commented Jan 21, 2014 at 11:43
  • This solution does work and should be the accepted answer.
    – tehlivi
    Commented Apr 12, 2017 at 21:05
  • 4
    Give me a 404, despite me resaving the permalinks. It does rewrite the URL in the browser (but not within the post permalink area), but still gives 404 in browser.
    – Garconis
    Commented Aug 7, 2018 at 18:07
  • Did not know this was possible for a taxonomy. I've used it with keeping the slug intact. Works good!
    – Loosie94
    Commented Sep 18, 2020 at 9:58

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.