0

I know that how to add add 'with_front' = false for WordPress custom taxonomy when adding them.

But how to apply WordPress 'with_front' = false for categories?

0

The register_taxonomy_args filter should do the job intercepting the arguments for the specified taxonomy:

add_filter( 'register_taxonomy_args', 'cyb_modify_category_args', 99, 2 );
function cyb_modify_category_args( $args, $taxonomy ) {
    if( 'category' === $taxonomy && is_array( $args ) ) {
            $args['rewrite']['with_front'] = false;
    }
    return $args;
}
  • I have never seen that passing something like function( $args, $taxonomy ) to a filter. Please can you explain little more how this work? What is the meaning of function( $args, $taxonomy ) – I am the Most Stupid Person Jul 12 '17 at 10:35
  • They are called anonymous functions, you can use whatever you want, anonymous functions or named functions, but anonymous functions are not recommend for filters and actions hooks if your code is for public release because they makes very difficult to unnregister them if someone wants to do it. – cybmeta Jul 12 '17 at 11:40
  • Answer updated using named function as callback, just in case you feel more comfortable. – cybmeta Jul 12 '17 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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