New answers tagged


The add_rewrite_rule function doesn't change the database. Just an array in memory. It is not an expensive operation. The alternative is to add code to detect whether your rule is there, which is actually more expensive than just modifying the array.


Well this is silly but I figured it out. I removed the last / from the pattern and now it works as expected. Code is now... add_rewrite_rule('^coaching/apply', 'index.php?page_id=5156', 'top'); Seems weird to me that ^coaching/apply would work but not ^coaching/apply/ esp when entering as the url works.


You only have one capture group, the ID is in matches[1], there is no matches[2]. EDIT- Here is the working version I tested in the 2016 theme. I created a page with slug sign-up, added the following to functions.php, then visited the Permalinks Settings page to flush rewrite rules. The value passed to product is available in the template via ...


I think you wanna do something like this: add_action('init', 'my_rewrite'); function my_rewrite() { global $wp_rewrite; // Your desired structure $permalink_structure = '/prodotti/%my_custom_variable%/%postname%/' // add the custom variable to wp_rewrite tags $wp_rewrite->add_rewrite_tag("%my_custom_variable%", '([^/]+)', ...

Top 50 recent answers are included