0

I want my taxonomy url to be like this: site.com/page/taxonomy_term

How will I be able to achieve this? I have written a wordpress rewrite rule code in my functions.php like this:

function sphere_custom_rewrite_rules( $rules ){
    $newrules['(.+?)/([^/]*)/?'] = 'index.php?pagename=$matches[1]&positive_sphere=$matches[2]';
    $newrules['(.+?)/([^/]*)/?'] = 'index.php?pagename=$matches[1]&negative_sphere=$matches[2]';

    return $newrules + $rules;
}
add_filter('rewrite_rules_array', 'sphere_custom_rewrite_rules');

the page doesn't return 404 error, but it doesn't do my functions in taxonomy.php instead it's doing my code on my template-page-name.php file. What I want is when I types this url:

site.com/page/taxonomy_term it'll run my code on taxonomy.php.

Any help would be greatly appreciated! Thanks.

1 Answer 1

1

You could use 2 of Wordpress' built in functions to get the result you're after.

add_rewrite_tag() and add_rewrite_rule()

There is an example of how to use these tags to get the result you want about halfway down this page https://codex.wordpress.org/Rewrite_API/add_rewrite_rule.

Note: remember to flush your rewrite rules.

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.