add_rewrite_rule() issue with parent/child/child page
add_rewrite_rule() issue with parent/child/child page
add_rewrite_rule() issue with parent/child/child page
wordpress path generation from rewrite rule
How to change an existing wordpress page rewrite rule?
In the tags of your answer there is <plugins> so I think you are trying to add custom rewrite rules from a plugin. In your question you say something about page template that is (generally) a theme-related matter. Of course you can create rewrite rules from a plugin and use them for a page template … Read more
Your regular expression is requiring the last slash be present which it will not be by default. So the path tides/mylocation/ is shortened to tides/mylocation and then tested. Instead, wrap the last part in an optional group using the ? and update the match number. add_rewrite_rule(‘tides/([^/]+)(/([^/]+))?’, ‘index.php?page_id=4348&location=$matches[1]&month=$matches[3]’, ‘top’);
Sally CJ commented an important detail that helped me reach what I needed. Apart from that I struggled with what seemed to be regex error – one of my rules was overriding another because there was no $ character in regex to end the string. Working solution for custom rewrites: function dd_custom_rewrite_rules() { add_rewrite_tag(‘%company%’, ‘([a-z0-9-]+)’, … Read more
I think I solved my problem. So if you have your WordPress post permalink set to %category%/%postname%/, and you want this for custom post type and taxonomy, you could prepare your rewrite links for all generated taxonomy terms (cat-a, cat-b etc.). Code: add_filter( ‘rewrite_rules_array’, function($rules) { $categories = get_terms([‘taxonomy’ => ‘success-category’ ]); foreach ($categories as … Read more
You don’t need to do this. As long as your site URL in Settings is set to mydomain.tld/wordpress you don’t need to include /wordpress in your rewrite rules. If you look at the rewrite_rules option in the wp_options table you’ll see that none of the default rules are using it, because it’s not required.
Check out my favorite Rewrite Analyzer plugin written by @Jan Fabry. It allows you to analyze your rewrite rules and really helps in debugging those rules.
404 error using Meta for Permalink rewrite