Using get_query_var() from a plugin

Hook into parse_query instead: add_action( ‘parse_query’, function() { add_rewrite_rule( ‘go/([^/]+)/?$’, ‘index.php?redirect_to=$matches[1]’, ‘top’ ); add_rewrite_tag( “%redirect_to%”, ‘([^&]+)’ );` } ); Reason: init is too early, query_vars haven’t been set yet. wp_head is too late, no can redirect at that point.

Flush rewrite rules on option update with Settings API

I register custom post type on init action and the validate which I’m writing about is set to register_setting inside admin_init action. This is the key to your issue. You’re registering the custom post type, and presumably you’re setting up the rewrite rules in that registration. When you call flush_rewrite_rules(), the rules are rebuilt right … Read more

Adding a rewrite rule to page that has no fixed variables and pagination

Got it to work, changing the regex from (.+) to (.*) Maybe helpful for others searching same rewrite on search and pagination. add_rewrite_rule(‘discover/interiors/interior-results/(.*)/page/([0-9]{1,})/?’, ‘index.php?pagename=discover/interiors/interior-results&tag1=$matches[1]&paged=$matches[2]’, ‘top’ ); add_rewrite_rule(‘discover/interiors/interior-results/(.*)’, ‘index.php?pagename=discover/interiors/interior-results&tag1=$matches[1]’, ‘top’ );

Relative links stop working after moving wordpress site from hosting to localhost

If you are in https://localhost/cc and use a relative lnk with href=”https://wordpress.stackexchange.com/login” (relative to current domain/site), the browser (not WordPress) will take you to https://localhost/login; if the link is href=”https://wordpress.stackexchange.com/questions/267557/login” (relative to current path) the browser will take you to https://localhost/cc/login. Relative links work like that, nothing to do with WordPress. That is why many … Read more