A
A
Andrey Suha2020-06-25 12:44:58
WordPress
Andrey Suha, 2020-06-25 12:44:58

How to resolve url?

There is a page on wp, for example, with the slug test, how can you make sure that when you navigate to /test/test2/.../any wp returns the test page template, and not a 404 error?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Suha, 2020-06-25
@andreysuha

add_action('init', 'do_rewrite');
function do_rewrite(){
    add_rewrite_rule( '^test/(.*)/?', 'index.php?page_id=5&sell_query_string=$matches[1]', 'top' );
    add_rewrite_tag( '%sell_query_string%', '([^&]+)' );
}

I
Igor Vorotnev, 2020-06-25
@HeadOnFire

Look at the template_include / template_redirect hooks and what happens on them. Well, yes, with the help of add_rewrite_rule or even add_rewrite_endpoint you can create additional rules that will be processed correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question