change home_url and site_url but don’t redirect to home_url and site_url on load

You need to set the WP_SITEURL and WP_HOME in wp-config.php file. Please add below code. define(‘WP_SITEURL’, ‘http://’ . $_SERVER[‘HTTP_HOST’]); define(‘WP_HOME’, ‘http://’ . $_SERVER[‘HTTP_HOST’]); In your server SSL setup then used below code define(‘WP_SITEURL’, ‘https://’ . $_SERVER[‘HTTP_HOST’]); define(‘WP_HOME’, ‘https://’ . $_SERVER[‘HTTP_HOST’]);

How to redirect?

You can do something like this, add_action(‘wp’,’special_redirect’); function special_redirect(){ global $post; if( $post->ID == 123 ) // put your post id { if ( ! wp_get_referer() ) // false if you access directly { wp_safe_redirect( get_home_url() ); // if so redirect to home } } } It should work. I’ve tested it.

Redirect after Permalink change – What regex do I use?

You can do this by regex rewriting the legacy URL as a query. You can do that either on the post_id or the postname, in this case I think the postname is probably safer (avoids false matches on some other path that might start with numbers). In custom functions, something like this: add_rewrite_rule( ‘^[0-9]+/(.*)/?’, ‘index.php?&name=$matches[1]’,’top’ … Read more

How to redirect new registrars to a custom registration page instead of WP default registration page?

Since wp-login.php control both login and registration, it is better to redirect the visitor to a login page from wp-login.php. You can use this code for redirecting your registration page – add_action(‘init’,’custom_registration_page’); function custom_registration_page() { $new_registration_page_url = home_url( ‘/register/’ ); global $pagenow; if( $pagenow == “wp-login.php?action=register” && $_SERVER[‘REQUEST_METHOD’] == ‘GET’) { wp_redirect($new_registration_page_url); exit; } } … Read more