URL Rewrite doesn’t work for nested pages

I have found my answer while searching. Thanks to this answer of @Milo: https://wordpress.stackexchange.com/a/50775/23214 pagename must include the full parent/child path. So, I had to change index.php?pagename=page-b… to index.php?pagename=page-a/page-b…. Changed it and works ok. Here is the Full code: add_filter( ‘query_vars’, ‘wpse26388_query_vars’ ); function wpse26388_query_vars( $query_vars ){ $query_vars[] = ‘var1’; $query_vars[] = ‘var2’; $query_vars[] = … Read more

How to always rewrite author archive page URL even if the author does not have a post

We managed this by hijacking the default author template and setting up our own. Set up a new url rewrite for team members: add_action(‘init’, function () { global $wp_rewrite; $wp_rewrite->author_base=”team”; $wp_rewrite->author_structure=”https://wordpress.stackexchange.com/” . $wp_rewrite->author_base. ‘/%author%’; }); In the template we then use: $uid = get_query_var(‘author’); to get the user’s id. From there you can build out … Read more

how to get archive urls with same origin for custom types and terms?

So, a first solution can be using add_rewrite_rules(). A first raw logic should be something like: 1- get term slugs you need, save in a var, say $terms_string; $terms_string should be a list of pipe-separeted slugs, suitable for regexp, like ‘type1|type2’ etc.. containing ONLY valid (allowed) values. Say use get_terms() to get all the slugs.. … Read more

How to change URL Custom Page?

You’re using the reserved public query variable name as your custom one. It can e.g. affect the canonical redirect by setting page_id and name for a different page. Change it to something else to avoid possible name collision, like kenan_video_slug: add_rewrite_rule( ‘^watch/([^/]*)$’, ‘index.php?pagename=watch&kenan_video_slug=$matches[1]’, ‘top’ ); Note that your rewrite will override the content pagination for … Read more