Understanding add_rewrite_rule

Posted by Prem Tiwari | Updated on

Understanding add_rewrite_rule. A basic rule that would work for your example:

This takes whatever comes after foo/ and sets that as pagename for the query, and then param gets the static value foo. If you need different URL patterns, you’ll need extra rules for each unique pattern. Refer to WP_Query docs for the various query vars that can be set within rewrite rules. Don’t forget to flush rewrite rules after adding new ones. This can be done by visiting the Permalinks Settings page.

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers