Site icon Anthony Carbon

Redirect selected pages or single page into specific page.

Redirect selected pages or single page into specific page. Example, redirect a selected pages or a single page after login into your dashboard page, membership page, or any page you desired.

You can use https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect this but this is only access once. Once you’ve login, you cannot repeat the redirection. Unlike `template_redirect` hook, this will fire every time they trying to access your selected pages or a single page and redirect it into your specific page.

By the way, here is the code below. Note that the `396` and `397` inside your array is the page ID of `dashboard`, and `membership` page in example. Make sure to put the correct page ID, and the `398` page ID is the page where you want to redirect.

add_action( 'template_redirect', 'my_page_template_redirect' );
function my_page_template_redirect(){
 	if( is_page( array( 396, 397 ) ) ){
		wp_redirect( get_permalink( 398 ) ); 
		// or just simple use whole permalink like below
		// wp_redirect( 'https://www.anthonycarbon.com/dashboard' ); 
		exit();
	}
}

Comment below if this post needs improvement.

Happy coding 🙂

Exit mobile version